Skip to content

Wrapping in JSONObject and JSONArray inconsistent #273

@johnjaylward

Description

@johnjaylward

I'm debating if we need the wrap method at all. In some cases (like object construction) wrap is called and will possibly leave the object untouched (Integer, BigDecimal, String, etc) or will wrap it into a JSONObject and sometimes converted to a string value (if it's package name starts with "java.", "javax.", or if the classloader is null).

This leads to inconsistencies in how not only data is placed into the JSON container types, but also in how they are written out.

I'm proposing that we remove the wrap method altogether and always insert values into the JSONObject and JSONArray as-is and handle conversion on the serialization output (write, toString, etc).

If we don't remove the wrap method, then I propose that we update all the put methods to wrap unknown objects (https://github.com/stleary/JSON-java/blob/master/JSONArray.java#L810 and https://github.com/stleary/JSON-java/blob/master/JSONObject.java#L1273 at least) to maintain consistency.

I think removing the wrap method is a better solution as the output already handles any conversions needed. This would make all serialization "lazy" instead of some lazy and some eager depending on what way values were added to an object or array.

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