Skip to content

How to output an API having names different than variable names?

I have an entity like the following

public class Class {
List<ClassData> classData;

I want to view this as “Data” in the output but instead, it gives “classData” as the field. I have tried a bunch of annotations but nothing seems to work. Please tell me how can I get this kind of output.



Required Output


Edit: I am getting the field with a different name and I need to give the output with some other name. For instance I am getting input as “ClassData” and giving output as “Data”


I got the way to do it!

Instead of using @JsonProperty using @JsonSetter for getting the input and then @SerializedName for renaming the data for the output

Thank you everyone for helping