I have a JSON API result to my android app that looks like the following (cut down to size)
{
"Results": [{
"data": [{
"AAA": {
"accessRole": "access.role.owner",
"fullName": "jsddd",
"spaceTotal": null,
"createdDT": "2016-05-29T02:52:11.000000Z",
"updatedDT": "2016-05-29T02:52:11.000000Z"
}
},
{
"AAA": {
"accessRole": "access.role.owner",
"fullName": "jsw",
"createdDT": "2016-05-29T04:48:57.000000Z",
"updatedDT": "2016-05-29T04:48:57.000000Z"
}
},
{
"BBB": {
"archiveId": 1,
"description": "the description here",
"createdDT": "2016-05-29T02:52:11.000000Z",
"updatedDT": "2016-06-01T22:49:01.000000Z"
}
}],
"message": ["Get successful"],
"status": true,
"createdDT": null,
"updatedDT": null
}],
"isSuccessful": true,
"createdDT": null,
"updatedDT": null
}
and am looking to convert the structure into something that is POJO (shown below) in my deserialize function as was defined by running this through jsonschema2pojo.org and then be able to use GSON on it
{
"Results": [{
"data": [{
"AAAs": [{
"accessRole": "access.role.owner",
"fullName": "jsddd",
"spaceTotal": null,
"createdDT": "2016-05-29T02:52:11.000000Z",
"updatedDT": "2016-05-29T02:52:11.000000Z"
},
{
"accessRole": "access.role.owner",
"fullName": "jsw",
"createdDT": "2016-05-29T04:48:57.000000Z",
"updatedDT": "2016-05-29T04:48:57.000000Z"
}],
"BBBs": [{
"archiveId": 1,
"description": "the description here",
"createdDT": "2016-05-29T02:52:11.000000Z",
"updatedDT": "2016-06-01T22:49:01.000000Z"
}]
}],
"message": ["Get successful"],
"status": true,
"createdDT": null,
"updatedDT": null
}],
"isSuccessful": true,
"createdDT": null,
"updatedDT": null
}
Was wondering if there is a way to do this elegantly instead of brute forcing by reading in the objects one by one and rebuilding it from scratch.
Bonus if it could be done w/o having to explicitly code in the data elements (AAA, BBB) as they will be growing in number over time.
Edited: The output that org.jsonschema2pojo is creating that doesn't match is in it making the elements as a single object not as as array.
package com.example;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
@Generated("org.jsonschema2pojo")
public class Datum {
private AAA aAA;
private BBB bBB;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public AAA getAAA() {
return aAA;
}
public void setAAA(AAA aAA) {
this.aAA = aAA;
}
public BBB getBBB() {
return bBB;
}
public void setBBB(BBB bBB) {
this.bBB = bBB;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}