Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 27 11:54
    scala-steward closed #295
  • Jul 27 11:54
    scala-steward commented #295
  • Jul 27 11:54
    scala-steward opened #304
  • Jul 13 12:51
    scala-steward closed #302
  • Jul 13 12:51
    scala-steward commented #302
  • Jul 13 12:51
    scala-steward opened #303
  • Jul 11 12:16
    scala-steward closed #287
  • Jul 11 12:16
    scala-steward commented #287
  • Jul 11 12:16
    scala-steward opened #302
  • Jul 05 15:17
    scala-steward closed #291
  • Jul 05 15:17
    scala-steward opened #301
  • Jul 05 15:17
    scala-steward commented #291
  • Jul 05 15:17
    scala-steward opened #300
  • Jul 05 15:17
    scala-steward opened #299
  • Jul 05 15:17
    scala-steward closed #296
  • Jul 05 15:17
    scala-steward commented #296
  • May 10 16:05
    scala-steward opened #298
  • Apr 07 14:05
    scala-steward opened #297
  • Apr 04 22:04
    scala-steward closed #289
  • Apr 04 22:04
    scala-steward commented #289
Miles Sabin
@milessabin
Heads up: 2.1.0 final has just been published :-)
Alexandre Archambault
@alexarchambault
Thanks! I should publish a new version today (after some minor adjustments)
Srepfler Srdan
@schrepfler
hi @alexarchambault, I've just started playing with Scala and having to deal a bit with XML I stumbled onto scalaxb, the xsd schema to type-classes+case-classes looks awesome but I've noticed the case classes sit within structures called DataRecord so in a way it mingles what is typically called the model and this DataRecord which looks like a metamodel facility to help with the inhering xml structure and ability to have various elements from different grammars (namespaces) sit on the same xml tree level
is there a way to use argonaut to take this generated model and convert it to for example JSON on the fly?
in a way ignoring the DataRecord classes
Alexandre Archambault
@alexarchambault
hi @schrepfler I had a quick look at a project of mine using scalaxb, with lots of generated case classes and ADTs
I can't find any field of type DataRecord in these
Srepfler Srdan
@schrepfler
hm
Alexandre Archambault
@alexarchambault
there are various issues I think you may run into trying to convert to JSON some of these
regarding some specific types scalaxb uses (javax.xml.datatype.XMLGregorianCalendar, scalaxb.Base64Binary, for example - you'll have to provide json codec for these specific types)
and also its ADTs: these are not sealed (it declares things like trait Something instead of sealed trait Something), which shapeless Generic will not like
but do you have a specific example of a generated case class with DataRecord? I can't find some in my model, but there may be in some others
Srepfler Srdan
@schrepfler
then you are lucky-er than me :))
Alexandre Archambault
@alexarchambault
(don't know if I'd been that lucky, I had to manually edit the generated code IIRC :-)
but if you have some generated code with a DataRecord, put it in a gist, I'll have a look at it
Srepfler Srdan
@schrepfler
let me show you an instance of how it composed the case classes in one instance
reqBetBuild: com.tralala.package.OxiModel = OxiModel(DataRecord(request,Request(ReqClientAuth(DataRecord(ReqClientAuthSequence1(tralala,someval,None,None,None)),Map(@returnToken -> DataRecord(N), @trustedMethod -> DataRecord(accountNo))),DataRecord(reqBetBuild,ReqBetBuild(Some(Token(List(DataRecord(11111111AD)),Map())),Some(CONTINUE),Some(M),None,None,List(DataRecord(outcomeGroup,OutcomeGroup(1,List(49285))), DataRecord(outcomeGroup,OutcomeGroup(2,List(49297))), DataRecord(outcomeGroup,OutcomeGroup(3,List(49291))), DataRecord(outcomeGroup,OutcomeGroup(4,List(49285, 49297, 49291)))),Map(@returnComplexCombinations -> DataRecord(Y), @returnFreebetTokens -> DataRecord(N), @returnOutcomeDetails -> DataRecord(N)))),Map())),Map(@version -> DataRecord(69.0)))
I think it's because the base document schema is very loose as well
Alexandre Archambault
@alexarchambault
@schrepfler you know you can format code multi-line code, with triple backquotes, like
code
and write multi-lines messages by pressing shift+enter to go to the next line
(that's better :-)
Srepfler Srdan
@schrepfler
sorry :)
new to gitter
Alexandre Archambault
@alexarchambault
no worries :-)
Alexandre Archambault
@alexarchambault
do you have the definition of ReqClientAuth? (grepping in the generated code, or ctrl+B from intellij)
Srepfler Srdan
@schrepfler
yup
case class ReqClientAuth(reqclientauthoption: scalaxb.DataRecord[Any],
  attributes: Map[String, scalaxb.DataRecord[Any]] = Map()) {
  lazy val returnToken = attributes("@returnToken").as[String]
  lazy val trustedMethod = attributes.get("@trustedMethod") map { _.as[TrustedMethod] }
  lazy val trustedHost = attributes.get("@trustedHost") map { _.as[String] }
}
Alexandre Archambault
@alexarchambault
maybe you could provide you own argonaut codec for DataRecord[Any]
then argonaut-shapeless will use it
Srepfler Srdan
@schrepfler
it's that Any which is worrying me
any example how the codecs are made?
Srepfler Srdan
@schrepfler
cheers
I'll try to convice first the scalaxb guys if they can bundle it as a util
Alexandre Archambault
@alexarchambault
(the argonaut API is not most accessible then, but once you learned to master it, it's nice)
Srepfler Srdan
@schrepfler
as a dev dealing mostly with Java, any Scala API looks like magical writings by some alchemist
Alexandre Archambault
@alexarchambault
it can feel this way at the beginning, type level libraries in particular :-D
bundling what btw? generation of json instead of xml?
Srepfler Srdan
@schrepfler
yes, being able to generate both JSON and XML from the same set of scalaxb model
Srepfler Srdan
@schrepfler
looking at the scalaxb sources
there are two definitons, one a trait
trait DataRecord[+A] {
  val namespace: Option[String]
  val key: Option[String]
  val value: A

  def as[B] = value.asInstanceOf[B]

  override def toString: String = {
    "DataRecord(" +
    ((namespace, key, value) match {
      case (None, Some(k), _) => k + "," + value.toString
      case (Some(n), Some(k), _) => "{" + n + "}" + k + "," + value.toString
      case _ => value.toString
    }) + ")"
  }
}
and a singleton
object DataRecord extends XMLStandardTypes {
  private case class DataWriter[+A](
    namespace: Option[String],
    key: Option[String],
    xstypeNamespace: Option[String],
    xstypeName: Option[String],
    value: A,
    writer: CanWriteXML[_]) extends DataRecord[A] {
    override def equals(o: Any): Boolean =
      o match {
        case that: DataWriter[_] =>
          namespace == that.namespace &&
          key == that.key &&
          value == that.value
        case _ => false
      }

    override def hashCode: Int = {
      var result = 17
      result = result + 31 * namespace.hashCode
      result = result + 31 * key.hashCode
      result = result + 31 * value.hashCode
      result
    }
  }
I get the feeling if this is implemented properly one would have to consider how do two namespaces share the projected names, possibly via a prefix
and omitting prefixes for the default namespace
Alec Zorab
@AlecZorab
@alexarchambault / @milessabin For reasons I don't wish to delve too deeply into, I have a 45 field case class that is primarily Strings, Doubles or Options of those. I'm seeing compile times on the order of 250seconds to derive a DecodeJson, using 0.2.0-SNAPSHOT (and therefore shapeless 2.2-M6). Is that to be expected?
Alexandre Archambault
@alexarchambault
possibly, I ran into similar compile time even not going as far as that (but with coproducts involved)
Wound ensuring the derived implicits aren't derived too often through proxying be an option for you?
Alec Zorab
@AlecZorab
uh. I'm not sure what you mean, so I don't know ;)