3

I am using jackosn and spring boot.

I want to recieve a request object that contains both meta object with information such as requestId and request time, and an object data. the object data changes between the different requests. I am talking about POST, PUT requests.

For example:

    {
    "meta" {
       "request_id":"11111",
       "time": 12312321 
    },
    "name":"A",
    "age":29
}


{
    "meta" {
       "request_id":"22222",
       "time": 12312321 
    },
    "color":"blue"
}

How can I achieve this without taking all my data classes and have the extend a base class? I do not want to do that because I do not wish to mix business data with request data.

I would like it to be something like this: define a generic request class:

public class ApiRequest<T> {

    protected  RequestMeta meta;

    protected  T data;

Where all the fields of the data will be mapped to the internal data object.
Please notice that this implementation require me to send all the business fields within a "data" JSON block and I wish them to be at the root.

Can this be done?

Regards, Ido

Ido Barash
  • 4,856
  • 11
  • 41
  • 78

0 Answers0