I am using Jackson 2.10.1 library to convert my Java POJOs to JSON and I am getting the below output, I require the output without the POJO name(MyTestPojo here), I have tried various jackson annotations like @JsonIgnoreProperties but those are mostly for the members present in the POJO and not the POJO class name.
{
"MyTestPojo": [
{
"CreatedBy": "user1",
"Name": "testABC",
"UpdatedBy": null,
"UpdatedDate": null,
"IsActive": true,
"Value": "testABC1",
"CreatedDate": "2017-03-13 15:41:54.0",
"Description": "testABC"
},
{
"CreatedBy": "user2",
"Name": "testABC",
"UpdatedBy": null,
"UpdatedDate": null,
"IsActive": false,
"Value": "testABC2",
"CreatedDate": "2017-03-13 15:41:54.0",
"Description": "testABC"
}
]
}
whereas what I require is -
[
{
"CreatedBy": "user1",
"Name": "testABC",
"UpdatedBy": null,
"UpdatedDate": null,
"IsActive": true,
"Value": "testABC1",
"CreatedDate": "2019-03-13 15:41:54.0",
"Description": "testABC"
},
{
"CreatedBy": "user2",
"Name": "testABC",
"UpdatedBy": null,
"UpdatedDate": null,
"IsActive": false,
"Value": "testABC2",
"CreatedDate": "2020-03-10 15:41:54.0",
"Description": "testABC"
}
]
}
Is there a way to handle this with Jackson annotations?
The POJOs that I have used are-
@JacksonXmlRootElement(localName = "ArrayOfTestPojos")
public class GetResponseVO {
@JsonProperty("MyTestPojo")
@JacksonXmlProperty(localName = "MyTestPojo")
@JacksonXmlElementWrapper(useWrapping = false)
private ArrayList<MyTestPojo> MyTestPojoList;
public ArrayList<MyTestPojo> getMyTestPojoList() {
return MyTestPojoList;
}
public void setMyTestPojoList(ArrayList<MyTestPojo> MyTestPojoList) {
this.MyTestPojoList = MyTestPojoList;
}
// standard getters and setters
}
and
@JacksonXmlRootElement(localName = "MyTestPojo")
public class MyTestPojo {
@JsonProperty("Name")
private String name;
@JsonProperty("Description")
private String description;
@JsonProperty("IsActive")
private int isActive;
@JsonProperty("Value")
private String value = null;
@JsonProperty("CreatedBy")
private String createdBy;
@JsonProperty("CreatedDate")
private String createdDate;
@JsonProperty("UpdatedBy")
private String updatedBy;
@JsonProperty("UpdatedDate")
private String updatedDate;
// standard getters and setters.
}
```````````
I am also generating the XML out of this so you can ignore the annotations relevant to XML.