Currently, I am utilizing Google's GSON package which can be found at this link
My task involves converting JSON data to Java objects.
Below is a snippet of the code where the conversion process takes place:
Gson gson = new Gson();
Type collectionType = new TypeToken<Collection<QueryProperty>>() {}.getType();
Collection<QueryProperty> queryProperties = gson.fromJson(query, collectionType);
The QueryProperty class includes these fields along with their respective getters and setters:
int id;
String uri;
String name;
Set<QueryValue> values;
String selected;
Prior to this, the QueryValue class had the following fields (with getters/setters):
int id;
String uri;
String name;
Now, I have a requirement to introduce different types of QueryValue instances.
Firstly, I aim to implement a NumericQueryValue class (as a subclass of QueryValue) to enable setting lower and upper bounds for database queries.
double lower;
double upper;
In addition, it is necessary to create a ResourceQueryValue class (also a subclass of QueryValue) that mirrors the original QueryValue structure:
int id;
String uri;
String name;
Is there a method to achieve this? I intend to keep the QueryValue class generic while dynamically determining the correct subclass based on the provided JSON parameters.
If my explanation is unclear, please feel free to ask for clarification.