0

I have the following (working code) with old JSONObject jar

String title = "title";
return new JSONObject()
                .put("title", title).put("url", null)));

When I start using the latest jar from JSON-java

I get a compile error

The method put(String, Collection<?>) is ambiguous for the type JSONObject

I found an issue that suggest using JSONObject.NULL instead of null

This library has a distinct JSONObject.NULL constant that is used to store JSON null values. It is deliberate. The Java null value is treated in this library like JavaScript undefined.

While not part of the specification, I can't see us undoing this as it would break backwards compatibility.

But there's no middle way to support both JSON versions? Should a bug be open for support backward for JSON-java project or am I missing something or just using unsupported old version?

1 Answer 1

1

put("", null) could any of the three methods in JSONObject class: put(String key, Object value) , put(String key, Collection<?> value) or put(String key, Map<?, ?> value). So it could not be used anymore with the latest version of org.json library. To overcome this, they have defined a static class Null of their own : org.json.JSONObject.Null which when used in put will call put(String key, Object value) method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.