java - JsonAnyGetter / JsonAnySetter the resulting JSON has doubled values -


i need write json string follows basic format:

"gesamtangebot":{     "angebotlist":[{         "instanzid":"string",         "buchungskontextlist":[{             "quellsystem":"something",             "payload":{}         }],         "payload":{"test1":"test1"}     }] } 

i'm using following class present data, , instance of class serialized jackson objectmapper.

@data public class angebot {      private string instanzid;      private list<buchungskontext> buchungskontextlist;      private map<string, object> payload = new hashmap<string, object>();      @jsonanygetter     public map<string, object> any() {         return payload;     }      @jsonanysetter     public void set(string name, object value) {         payload.put(name, value);     } } 

if serialize instance of class as-is, resulting json this:

"gesamtangebot":{     "angebotlist":[{         "instanzid":"string",         "buchungskontextlist":[{             "quellsystem":"something",             "payload":{}         }],         "payload":{"test1":"test1"},         "test1":"test1"     }] } 

as can see data of "payload" doubled it's own element , don't have idea why.

thanks in advance attention , advice.

it seems want serialize payload normal map. if don't want there twice should not have any() method, have regular getter method payload.

the any() method can used in case want serialize items payload map appear properties of angebot class. use any method, , not have getter payload.

your json come out this:

"gesamtangebot":{     "angebotlist":[{         "instanzid":"string",         "buchungskontextlist":[{             "quellsystem":"something",             "payload":{}         }],         "test1":"test1"     }] } 

and test1 variable of angebot class.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -