Configure json on Play framework (scala) -


checking play documentation found can automate json de/serizalization following code:

implicit val addresswrites = json.writes[address] implicit val addressreads = json.reads[address] 

a friend told me add on companion object, should add 1 companion obj each class add json config? couldn't add models in 1 place or use annotations on each class in java?

and general config like: implicit val config = jsonconfiguration(snakecase)

where add that?

regarding put serializer/deserializer implicits, have few suggestions:

  1. declare everytime need use it
  2. add companion object , implicit available when import data class
  3. declare in single jsonserializers object , import whenever need use it.

using companion object makes easy remember import make implicits available when needed (typically in controller class) , "encapsulates" code related model in single file.

having single jsonserializers object has advantage of making possible have serializers available in single import, adds point of maintenance when model needs deleted, renamed or added.

regarding second question, declare configuration implicit, need it, before implicit serializers.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -