scala - Play Framework automatic JSON marshalling -
i'm looking set straight on understanding of how play framework handles conversion of scala objects json , vice versa (specifically restful apis):
i've read on , on again across web using play's json support nothing pleasure. coming spring have built in httpmessageconverter
(specifically mappingjacksonhttpmessageconverter
) auto marshall requests , responses in controllers hardly effort.
play, on other hand, (it appears) requires write read , write converters every class intend marshal. e.g. (from play docs):
implicit val locationwrites: writes[location] = ( (jspath \ "lat").write[double] , (jspath \ "long").write[double] )(unlift(location.unapply))
to me seems tedious when compared built in automatic message converting capabilities of spring. understanding play uses jackson under hood can same accomplished scala / play, or perhaps premise flawed?
you can use writes
macro:
implicit val locationwrites = json.writes[location]
i've never used spring, according the docs mappingjacksonhttpmessageconverter
, work typed beans , untyped hashmap
instances. play! has built in writes
instances scala map
instances, , writes
macro can create instances case classes, functionality similar. however, guess case classes have less boilerplate typed bean, line create implicit writes
instance.
Comments
Post a Comment