I have an entity like the following
@Data @NoArgsCounstructor @AllArgsConstructor public class Class { @JsonProperty("Data") 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.
Output
{ "classData":[] }
Required Output
{ "Data":[] }
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”
Advertisement
Answer
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