1

I have a piece of code that looks as follows"

public enum MyEnum {
    EXAMPLE("example1", false, -1L);
    private final String name;
    private final boolean deprecated;
    private final long id;
...
}
...
MyEnum myenum = MyEnum.EXAMPLE;
try {
    params.put("myenum", myenum);
    JSONArray paramArray = new JSONArray();
    paramArray.put(0, params);
    JSONObject request = new JSONObject();
    request.put("params", paramArray);
    log.info(request.toString());

} catch (JSONException e) {
    e.printStackTrace();
}

If I run this code directly with java -cp Bla Main.Class, I get the expected output:

{"params":[{"myenum":"example1"}]}

However, when I build this into a super jar with Gradle I get:

{"params":[{"myenum":"EXAMPLE"}]}

So there seems to be some witchcraft going on with the classpath and competing versions of org.json. In the first case, the toString of the enum is applied correctly, in the second case, the enum is using the default toString method.

Anyone an idea how to debug that?

Martin Schäf
  • 365
  • 1
  • 12

0 Answers0