I have the below code which I want to serialize.
class .. {
public transient long id;
public Date steps;
public int days;
public List<Integer> next;
}
I output this to JSON string using the below code.
String json = new Gson().toJson(obj)
The output which I get is as under
{"days":2, "next": [3,5,8], "steps": "Nov 24, 2020 9:50:09 PM"}
As you can see, it is sorting output in alphabetic order. I do no want this. I want it to be in order I defined in the class i.e.
{"steps": "Nov 24, 2020 9:50:09 PM", "days":2, "next": [3,5,8]}
How can this be achieved ?