java - Jackson's @JsonAppend with default value -


guys! developing web application , decided use jackson json processing framework.

in request data willing send; let's pojo looks this:

data class jsonenvelope(         @jsonproperty("obj1")         val obj1: obj1,          @jsonproperty("obj2")         val obj2: obj2) 

which serialized this:

{     "obj1":{...},     "obj2":{...} } 

but need add metadata object, let's fields meta1 , meta. thought @jsonappend solve problem, using jackson jersey, not serializing objects manually, cannot use writer.withattribute("...", ...).

i aware of this thread, there no answer kinda satisfy needs, because think, writing custom serializer bit overkill this, if not have mechanism "serialize rest of original object". i'd glad ideas

the solution in the answer cited, adds mixin objectmapper uses objectwriter configure it, solution.

for jersey, calls objectmapper.writerfor , therefore prevents calling withattribute in order configure objectwriter, 1 alternative add attribute objectwriter before returning writerfor. suggest subclassing objectmapper , overriding various writerfor methods, adding necessary attribute @ point. can jersey use objectmapper registering jax-rs provider: see various annotations in javax.ws.rs started on this. this answer gives example of do.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -