In my project, I am dealing with objects (like a ball) that have specific data members and functions. These objects are being retrieved from various servers, each with its own hierarchy. For example:
class Ball {
int size;
string color;
}
An instance of this class in JSON would look like this:
{ ball: {
size: 3,
color: red
}}
The challenge arises when I encounter a different hierarchy for the same type of object. For instance, another server may provide a Boll object with these attributes:
Class Boll{
int mass;
View color;
}
Class View {
string color;
}
This results in a JSON object like:
{ Boll: {
mass: 3,
view: {
color: red
}}
Despite the varying hierarchies, it is clear that these classes share similarities.
I initially attempted to create a Map<string, string>
where I could match up attributes between the two classes. However, as the objects became more complex (e.g., with nested objects like "view"), my solution became insufficient. With the complexity of objects in my project, I need a new approach to effectively handle these diverse object structures.