Home > Software engineering >  Handle dynamic request body - java rest api
Handle dynamic request body - java rest api

Time:11-25

I have a dynamic request body as below. It can be either

{
   "emp_id" : "1234",
   "ids" : ["555", "666"]
}

or

{
   "name" : "john",
   "ids" : ["333", "444"]

How can I handle this in request pojo class? Can someone help on this?

CodePudding user response:

How about this?


class Foo {
    @SerializedName("emp_id")
    private String empId;
    @SerializedName("ids")
    private List<String> ids;
    // getter setter    
}
  • Have you ever try any the Json processing library before? (Jackson, gson,...)

CodePudding user response:

Any setter and getter by json should help you .

Please find the details Any Setter & Getter

  • Related