I have an object that I'd like to generate a JSON object for. Currently I have an object that is wrapped by another object, a ResourceObject. This resource object only has a subset of the exposed variables on the top level object.
I use this resource object to generate the json by annotating it. This is to keep the original object cleaner as it's used in other places in the code. However, maintaining this filtering code increases complexity and is mostly boilerplate code.
Ideally, I'd like to pass the object and the expected schema to do the filtering for me, but I don't see anything like that available. I'm hoping my search criteria is just not correct.
Example Class1
Class1 {
private String name = "C1";
private String version = "1.0";
public String getName() {
return name;
}
public String getVersion() {
return version;
}
}
Example Resource class
ResourceClass1 {
private Class1 class1;
ResourceClass1 (Class1 c1) {
class1 = c1;
}
public String getName() {
return class1.getName();
}
}
Example Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Class1",
"type" : "object",
"properties" : {
"name" : {
"type" : "string"
},
}
}
Right now, getting the JSON from the Resource class gives me something to the affect of:
{
"properties" : {
"name" : "C1"
},
}
Is there a package which would get me the same json by passing in only the schema and java object?