-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
When I use an Enum with a "getter"-method and put this value into a set and this set as a value of a JSONObject the String representation of the Enum is not the same as when I put the Enum directly as a value of the JSONObject. This issue depends on the wrap method of JSONObject that is called when a JSONArray (used for the Set) is created from a collection.
Here is an example.
enum ToStringEnum{
a,
d(false);
private final boolean flag;
ToStringEnum() {
this(true);
}
ToStringEnum(boolean disabledOnDefault) {
this.flag = disabledOnDefault;
}
public boolean isFlag() {
return this.flag;
}
}
ToStringEnum a = ToStringEnum.a;
JSONObject object = new JSONObject();
Set<ToStringEnum> set = new HashSet<ToStringEnum>();
set.add(a);
object.put("testset", set);
object.put("test", a);
System.out.println(object.toString());
//result: {"testset":[{"flag":true}],"test":"a"}
//expected: {"testset":["a"],"test":"a"}
Metadata
Metadata
Assignees
Labels
No labels