spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
974 stars 190 forks source link

Implicit conversion on unmarshalling #210

Closed edenfisher closed 7 years ago

edenfisher commented 7 years ago

Hey, I'm using spray-json with akka-http to parse and unparse json objects. The problem im trying to unmarshall is Array[Array[String]]. I have an implicit conversion function that convert this kind of object to Array[TimeRange](Time Range is a class I made). I want the spray library to automatically use my conversion function whenever it trys to unmarshall the original object. I hope you understand. Thanks for the help

ktoso commented 7 years ago

That's something you could build on top of spray-json, but I don't think it belongs into the core.

Just provide implicits or methods which would do that. We do so in Akka HTTP - Unmarshal(bla).to[MyValue] etc.

edenfisher commented 7 years ago

Thanks for the response, but this does not quite help me. I'll try to explain it more clearly. I want to convert the class type im getting from the request to my type which is a little different. Im receiving class A with few properties. One of the properties is of type Array[Array[String]](lets call it X). I'm trying to parse the json to class B which is like A but instead of property X it has property Y which is of type Array[TimeRange]. How do I manage to make akka automatically unmarshal the object as Type A and then converts it to type B. Thanks