I need a function, that reads a json file and control the structur of the json file. Required fields should be defined. For that I found a question that resolve a part of my problem Gson optional and required fields. But in this case the naming convention has not power any more. In my case I used following GsonBuilder:
this.gsonUpperCamelCase = new GsonBuilder()
.registerTypeAdapter(TestClass.class, new AnnotatedDeserializer<TestClass>())
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create();
Every key-value from JSON, that is in this case the deserialized java object need to be lowercase. Otherwise it will throw JsonParseException.
For example I have this class:
class TestClass {
@JsonRequired
private String testName;
//getter & setter
Then this JSON-file can not be deserialized:
{
"TestName":"name"
}
But I want to get sure that UPPER_CAMEL_CASE is used in this case. Thx.