I am building a JSON-RPC over UDP socket API in Java. There are 6 objects that will be transmitted in JSON:
Under most of these, the following fields would be added to the message and be of types String and Integer:
Ideally, these would all be parsed and generated within the same class file, Json.class
What I normally do in other languages would be to use a struct for each one. In Java, I learned that the guidelines permit using a subclass with instance variables in place of Java's absence of structs. Another way I have thought of would be to use many getter and setter methods.
Unfortunately, the project I am contributing to does not allow sub classes to be used in place of structs. Also, I would prefer not to bloat the class file with too many getter/setter methods.
As I'm just learning Java, I do not know what the most efficient way of doing this is under my circumstances.
My question: is there another way of achieving this without getters/setters, sub classes, and separate class files?