Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

[question] How to serialize this mix? #13

Closed
gaydenko opened this issue Aug 19, 2014 · 9 comments
Closed

[question] How to serialize this mix? #13

gaydenko opened this issue Aug 19, 2014 · 9 comments

Comments

@gaydenko
Copy link

Hi! I'd want to serialize this mess:

  case class In(i: Option[String])
  case class Out(boo: Boolean, in: In)

  val mess = Map(
    "s" -> "aString",
    "inSome" -> In(Some("forty two")),
    "inNone" -> In(None),
    "arr" -> Seq(11, 22, 33)
  )

I have tried

    val j = muster.codec.jawn.JawnCodec
    println(j.from(mess))
    val ja = muster.codec.jackson.JacksonCodec
    println(ja.from(mess))

but have got:

{"s":{},"inSome":{},"inNone":{},"arr":{}}
{"s":{},"inSome":{},"inNone":{},"arr":{}}
@gaydenko gaydenko changed the title How to serialize this mix? [question] How to serialize this mix? Aug 19, 2014
@casualjim
Copy link
Member

yeah Map[String,Any] I don't know how to do yet. That would require runtime reflection I think.

@gaydenko
Copy link
Author

Not sure it is for the next issue, so asking here :)
In fact, I have tried Map and Seq as far as not found hash-like and array-like case classes in muster.ast (lets omit case classes for now). These containers are needed to craft arbitrary tree. Have I missed something?

I can clarify the intention. There are (far to be rare) use cases a resultant map is dynamic, i.e. a list of Tuple2 (as a base of the map) is creating at runtime. And the aim is to serialize such maps. At this case a model can not be modeled as a case class.

@casualjim
Copy link
Member

o they exist: https://github.com/json4s/muster/blob/master/core/src/main/scala/muster/ast/ast.scala#L398-L400

But they are kind of deferred to each implementation so that for arrays for example it doesn't read the entire array but just the element it's trying to deserialize at that moment.

For jawn their implementation is this:
https://github.com/json4s/muster/blob/master/codecs/jawn/src/main/scala/muster/codec/jawn/jawn_input.scala#L12-L69

@gaydenko
Copy link
Author

Yes, I have found those abstract classes. But they are abstract, and those jawn implementations your are pointing to are private. How to become happy? :)

@casualjim
Copy link
Member

Your use case is dynamic json generation right?
Why not build a jawn ast and then get muster to serialize it?

@gaydenko
Copy link
Author

Yes, it is one of the use cases.
Thanks for the tip. I'm new in these areas and need more minutes to try it.

@gaydenko
Copy link
Author

Heh... Still hasn't found a way muster can serialize an AstNode[_]...

@casualjim
Copy link
Member

O I'm terribly sorry I haven't implemented an integration with the jawn ast integration. there is integration with the json4s ast, play-json ast and argonaut ast.
it's missing an implementation like this one: https://github.com/json4s/muster/blob/master/codecs/json4s/src/main/scala/muster/codec/json4s/package.scala

@gaydenko
Copy link
Author

Aha! Thanks for the clarification! Now I see I have tried to look for a black cat in a black room while there isn't a cat at all there :)
But I can't implement it myself yet..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants