How to set up Json serialization using Scala and Play Framework?

I would like to serialize some Scala class classes for Json. For example, my case class looks like this:

case class Item ( id: Int, name: String, price: BigDecimal, created: java.util.Date) 

and I would like to serialize it for Json as follows:

 {"id":3, "name": "apple", "price": 8.00, "created": "123424434"} 

so I need custom serialization for BigDecimal and for Date . Where do I want data in milliseconds since January 1, 1970.

When using Scala and Play Framework, I can return Json using Json(myObject) , but how do I set up serialization? Or is there a recommended Scala library?

+6
source share
1 answer

For extended json playscala, it is recommended to use external json libraries, for example, lift-json .

There are also some related topics, you can take a look at them. I believe this Play JSON serialization setting has the answer to your question.

+1
source

Source: https://habr.com/ru/post/891016/


All Articles