Nested case class /collection serialization

28 views
Skip to first unread message

biswa...@gmail.com

unread,
Jul 14, 2016, 7:20:21 AM7/14/16
to scala-salat
Hello,

I'm trying to write a decoder for kafka(bytes to case class) .  I have written something like this and its working fine ( actual message is in protobuff)

     private[decoder] val decoder = new PBDecoder[java.util.Map[String,Any]](
      classOf[Schema.Click],
      new TypeReference[java.util.Map[String,Any]]() {})

  def fromBytes(bytes: Array[Byte]): java.util.Map[String,Any] = {
    decoder.fromBytes(bytes)
    
  }

message structure  is nested something like below :

{  
   timestamp=1468389261962,
   click=281651856214611047,
   fingerprint=   {  
      id=,
      metadata=      {  
         
      }
   }

However , consdiering  some downstream manipulation @ spark streaming I'm planning convert the same to case class  , that's how I came across to salat , what I noticed it is not able to deserialize nested structure , works fine for  normal collection and data types . Also , some of my element is optional , seems like option is not working also .

By any chance I can make it work for nested structure ?

case class Click(
timestamp: Long,
device_fingerprint:Option[LinkedHashMap[String, Object]],
type: String)


Thank you 

Noah Zucker

unread,
Jul 14, 2016, 7:27:08 AM7/14/16
to scala...@googlegroups.com

Nested collections are not supported at this time. Check out the readme and wiki.

Optional collections are likewise not supported. Instead of optional collections, you should use Nil or Map.empty.

These limitations bit me enough that I improved the error message text in Salat 1.9.10 - just released.

Reply all
Reply to author
Forward
0 new messages