I have some enum class, let's imagine
public enum MyEnum {
ONE("one"), TWO("two"), THREE("three"), DEFAULT("some value")
//..
}
and Dto class:
@JsonPropertyOrder(value = {"id", "name", "params"})
public Dto {
private Long id;
private String name;
private Map<MyEnum, Object> params;
}
How can I setup order for keys in params map? I know that LinkedHashMap can be used to setup order and just add to map in proper order. But! There are cases, when key-value should be added in runtime and it should be added to params map not to last link, but inside map. e.g.
params = new LinkedHashMap();
params.put(ONE, new String("object1"));
params.put(THREE, new String("object #3"));
and than in another place of code we just added
params.put(TWO, new Integer(20));
and order inside json should be:
{
"id":"123", "name":"some name",
"params":{"ONE":"object1","TWO":"20","THREE":"object #3"}
}