Hi,

I just checked some code on 2.3-dev branch:

https://github.com/akka/akka/blob/release-2.3-dev/akka-http-marshallers-java/akka-http-jackson/src/main/scala/akka/http/javadsl/marshallers/jackson/Jackson.scala
https://github.com/akka/akka/blob/release-2.3-dev/akka-http-marshallers-scala/akka-http-spray-json/src/main/scala/akka/http/scaladsl/marshallers/sprayjson/SprayJsonSupport.scala

It seems that akka-http use jackson to support java bean 
marshall/unmarshall and use spray json to support scala classes, right?
Or the spray json can support both?

I have some questions:

1. What if I have cases that scala class and java class are mixing used, 
for example a case class reference a java bean, or java bean reference a 
scala class.
2. Do you have some implicit function which can act like a facade, and 
determine which json serializer to use by the input object or class?


I'm asking this is because I'm using json4s to do the marshall/unmarshll 
for my spray project.
And it turns out that json4s does not support plain java bean well, I have 
to optionally to choose which serializer to use, something like:


  private implicit def json4jMarshaller[T <: AnyRef](obj: T): Marshaller[T] 
=
    if (isJavaClass(obj))
      Marshaller.delegate[T, String](ContentTypes.`application/json`)(new 
ObjectMapper().setVisibility(PropertyAccessor.FIELD, 
Visibility.ANY).writeValueAsString(_))
    else
      Marshaller.delegate[T, 
String](ContentTypes.`application/json`)(org.json4s.jackson.Serialization.write(_))

  private def isJavaClass(v: Any): Boolean = {
    import reflect.runtime.universe._
    val typeMirror = runtimeMirror(v.getClass.getClassLoader)
    val instanceMirror = typeMirror.reflect(v)
    val symbol = instanceMirror.symbol
    symbol.isJava
  }


The purpose of doing this is to give user a unified entry instead of:

Ah, this is a java bean, and I'll import  JacksonProtocol._ 
oh, this is a scala case class, I should import json4sProtocol._


I'm just curious that whether akka-http has some solution to make it 
smoothly.

Thanks a lot!

Leon



-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to