java - Spring template engine for rendering JSON -


i come ruby , have started testing spring , find nice.

however i'm used being able customize rendered json output libraries rabl , feels wrong expose internal models straight out json annotation @responsebody , returning model.

does have tips on libraries similar rabl java/spring or there existing way spring without manually writing templates in json?

spring uses jackson json (de-)serialisation. take @ jackson wiki; describes several ways customise way json generated or interpreted.

as understand comment, have couple of customisations in mind.

  • renaming fields can achieved annotating field @jsonproperty("name")
  • not rendering fields can achieved annotating field @jsonignore

but these require touch model. far know, there no way achieve without @ least changing model classes slightly. there's concept of "views" in jackson still require putting annotations on model. in practice, i've never experienced problems java classes being annotated both jpa , jackson annotations, way.

finally, can consider creating 2 versions of model - 1 comes database (or whatever source of data have), , 1 used interact user interface. however, require layover of transformers or converters. whether or not option you.


Comments