Skip to content

warp of Sets of Enums is broken #255

Description

@Simulant87

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"}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions