Skip to content

JSONObject.wrap does not handle enums #145

@twoseascharlie

Description

@twoseascharlie

Steps to reproduce:
Create a new JSONObject();
try to add an enum as a value
dump the jsonObject via the toString() method

expected:
we see the enum values

actual:
we do not see the enum values

Please see below stack. It seems that the JSONObject.wrap function fails to recognize the enum and tries to use the bean constructor from the JSONObject class. My enum does not have getters/setters like (since it is not a bean) and so nothing gets dumped from the toString()

JSONObject.wrap(Object) line: 1730
JSONArray.(Collection) line: 159
JSONObject.writeValue(Writer, Object, int, int) line: 1767
JSONObject.write(Writer, int, int) line: 1836
JSONObject.toString(int) line: 1614
JSONObject.toString() line: 1591
JSONOutputRenderer.buildVariantsArray(Set) line: 100
JSONOutputRenderer.getJson(BuildInfo) line: 83
JSONOutputRenderer.generateBuildInfo(String, BuildInfo) line: 50
GenBuildOutputHandlerMain.outputBuildInfo(String, BuildInfo) line: 24
GenBuildOutputHandlerMain.processFile(String) line: 18
GenBuildOutputHandlerMain.main(String[]) line: 34

I have pulled the latest source and built the following suggestion to fix the bug:

Added at line 1722 of JSONObject.java
if(object instanceof Enum){
return object.toString();
}

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