I use Jackson 2.9.8
for converting my below POJO
as JSON
:
public class ResponseEntity implements Serializable {
private static final long serialVersionUID = 1L;
private int total_record_count;
private int filtered_record_count;
@JsonProperty("list")
private List<Map<String,Object>> entityList;
public ResponseEntity(List<Map<String,Object>> entityList) {
this.entityList = entityList;
this.filtered_record_count = entityList.size();
}
public int getTotal_record_count() {
return total_record_count;
}
public void setTotal_record_count(int total_record_count) {
this.total_record_count = total_record_count;
}
public int getFiltered_record_count() {
return filtered_record_count;
}
public void setFiltered_record_count(int filtered_record_count) {
this.filtered_record_count = filtered_record_count;
}
public List<Map<String, Object>> getEntityList() {
return entityList;
}
public void setEntityList(List<Map<String, Object>> entityList) {
this.entityList = entityList;
}
}
In the result JSON
, value of entityList member is mapped to list key as it's annotated with @JsonProperty("list")
:
{
"list" : [ {
"id" : "IID000000002129959",
"attr1" : "MY",
"attr2" : "sd",
"attr3" : true }]
}
But I need to customise it with different names. For some response it should be busines1
, business2
, etc.
How do I make JsonProperty
name dynamic?