I have a JSON string coming from a server, and I have no control over it.
I generated the Java classes through programmatic usage of the jsonschema2pojo library.
I am using GSON to deserialize the JSON into my Java objects.
Here is an example of the JSON.
"description_by_id": {
"50": {
"field1": "value1",
"field2": "value2",
"field3": "value3"
}
}
That "50" subclass is actually just 1 of 18 classes that are similarly named as a number.
When jsonschema2pojo generates the Java class, it understandably prepends an underscore to create the class name (so, _50).
jsonschema2pojo generates the DescriptionById class with this member:
@JsonProperty("50")
private com.me.models._50 _50;
And the getter looks like this (setter is similar):
@JsonProperty("50")
public com.me.models._50 get50() {
return _50;
}
I am using GSON like this:
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
But the _50 object and the other 17 like it are all null after GSON is done, and I have checked that the corresponding spots in the JSON are actually filled in with real values.
Is there anything along this chain that I can do to get it working properly without needing to manually hack around the issue?