java - Change JSON key without changing variable name in POJO -
this question has answer here:
- change field name in json using jackson 3 answers
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
Post a Comment