java - Change JSON key without changing variable name in POJO -


this question has answer here:

i have class definition

class employee {  string id;  string name;  int age;  //getters , setters } 

i want create json object out of follows

{   "id" : "a12",   "employee_name" : "abhishek"   age : 97 } 

notice employee_name not correspond pojo variable name. can add annotation me ? like

@jsonkey(value="employee_name") string name 

give solutions related gson and/or jackson.

in jackson use @jsonproperty

e.g.:

@jsonproperty(value="employee_name") string name 

with gson use @serializedname

@serializedname(value="employee_name") string name 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -