How do we return JSON of custom format while returning JSON in NINJA FRAMEWORK controller.
return Results.json().render(MyPOJO);
MyPOJO class
@Entity
public class MyPOJO {
private String Name;
private String Value;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getValue() {
return Value;
}
public void setValue(String Value) {
this.Value = Value;
}
}
Current JSON Output
[{"Name":"Person1", "Value":"Value1"}, {"Name":"Person2", "Value":"Value2"}]
Custom JSON Output (Required)
[{"1":"Person1", "2":"Value1"}, {"1":"Person2", "2":"Value2"}]
Jorge is right - Ninja just uses Jackson to serialize stuff - you can use all goodies of Jackson to customize parsing and rendering of your entities.
In your case the solution is simple. Just use @JsonProperty like that:
}