Skip to content

Inconsistencies in how null is handled from implementations of JSONString #275

@johnjaylward

Description

@johnjaylward

This is related to #273, but could be fixed separate from it if needed. It was first discovered by @run2000 while working on PR #241.

Currently output from the library is generated using 2 different methods JSONObject.valueToString (used mostly when inserting new objects to a JSONObject or JSONArray) and JSONObject.writeValue (used by toString and other write operations). Each of these methods have their own implementation for how values are processed and for most things the implementation matches. However, for JSONString implementations, we see two different approaches used for null checks from the JSONString.toJSONString.

In valueToString there is an instanceof String check that occurs and if it fails, a JSONException is thrown.

In writeValue if value.toJSONString() returns null, then the quoted value of value.toString() is used instead. No exception is thrown.

The Java Documentation on JSONString does not explicitly dictate how null values returned from implementations should be handled, but it does seem to imply that the value.toString() is correct and not the Exception.

This issue is to discuss what type of handling should be used to make this API call consistent as well as to note any possible change to the documentation.

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