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

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -