jdereg / json-io

Convert Java to JSON. Convert JSON to Java. Pretty print JSON. Java JSON serializer. Deep copy Java object graphs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in JsonWriter.formatJson() for enum

xeronix opened this issue · comments

public class TestClass {
    private int a;
    private TestEnum enumObj;
    
    public TestClass() {
        a = 10;
        enumObj = TestEnum.GREEN;
    }
}
public enum TestEnum {
    GREEN;
}

Following code fails:

TestClass obj = new TestClass();
String objStr = JsonWriter.objectToJson(obj);
JsonWriter.formatJson(objStr)

Exception in thread "main" com.cedarsoftware.util.io.JsonIoException: Class 'com.ifn.dev.TestEnum' does not have primitive wrapper.

If i pass the pretty print argument then it works fine:

Map<String, Object> jsonWriterArgs = new HashMap<>();
jsonWriterArgs.put(JsonWriter.PRETTY_PRINT, true);      
String objStr = JsonWriter.objectToJson(obj);

I am using JDK 8.

json-io 4.14.0 has been released. Fixes for enum handling and support for JDK's through 17 are included. Please let me know if this is an issue for you.

json-io 4.14.2 fixes EnumSet.