Is there any way to serialize a class into json but only with fields I want to use in particular case without need of creating multiple variations of class? Let's take an example:
class User{
@JsonField
private String name;
@JsonField
private String surname;
@JsonField
private String hashedCode;
@JsonField
private String city;
@JsonField
private String anotherDummyString;
}
Now in one of my methods I would like to have a mapping to json Object which only contains name, city and anotherDummyString.
In Second method I want to have surname and city. In third method ... .
Is there any pleasant and neat way to achive this? I was wondering if I can "hide" these fields which I don't need.