Scala: serialize case class to JSON , alternate names -
Scala: serialize case class to JSON , alternate names -
any way serialize scala case class json , have ability provide custom serialized names ?
for example, in java can done using gson library :
public class someclasswithfields { @serializedname("name") private final string somefield; private final string someotherfield; public someclasswithfields(string a, string b) { this.somefield = a; this.someotherfield = b; } }
i tried doing in scala :
case class someclasswithfields(@serializedname("name") somefield:string)
but seems have no effect .
any thoughts ?
you can spray-json calling jsonformat overloads.
here's how work example:
import spray.json._ case class someclasswithfields( somefield:string) object someclassjsonprotocol extends defaultjsonprotocol { implicit val someclassformat = jsonformat(someclasswithfields,"name") }
json scala serialization gson
Comments
Post a Comment