java – Best practices for JSON-RPC JSON objects

I'm building a JSON-RPC socket API on UDP in Java. There are 6 objects that will be transmitted in JSON:

  • jsonRequest

  • jsonSuccessResponse

  • jsonError

  • jsonErrorResponse

  • jsonNotification

  • jsonSubscription

Under most of these, the following fields would be added to the message and would be of type String and Integer:

  • Version

  • Message

  • Result

  • The data

  • Settings

  • ID

Ideally, these would all be parsed and generated in the same class file, Json.class.

What I normally do in other languages ​​is to use a structure for each one. In Java, I learned that the instructions allow to use a subclass with instance variables in place of the absence of struct in java. Another way I thought would be to use a lot of getter and setter methods.

Unfortunately, the project I contribute to does not allow the use of subclasses instead of structs. In addition, I would prefer not to overload the class file with too many getter / setter methods.

As I have just learned Java, I do not know what is the most effective way to do it in my case.

My question is: is there another way to do this without going through accessors / configurators, subclasses and separate class files?