Skip to main content

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?

  • From: Jonathan Fuerth < >
  • To:
  • Subject: [jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?
  • Date: Tue, 15 Jan 2013 16:44:16 -0500


On 2013-01-15, at 2:42 PM, Jitendra Kotamraju wrote:

On 01/15/2013 11:29 AM, Jonathan Fuerth wrote:
" type="cite">

In the example that deals with null vs. missing entries [1], I see they do indeed use the Option type to represent the possibility of a missing entry. As I said before, this is really great but not something we should dive into in a Java API. At least not until there's an Option<T> in the standard library.
Yes, I agree on that.

It appears this is coming in JDK8 (it's called Optional<T>), and that's all the more reason we shouldn't introduce our own in this API.

" type="cite">

Digging into the code [2], it appears that lift-json treats null as equivalent to JNull.

But all this aside, I feel like we should be looking for precedent for use of a Null object in the Java SE and Java EE libraries, not in Scala frameworks.

I still think that taking the same approach as java.util.Map for null-vs-missing values is best, especially for an object that implements java.util.Map.
I think that allowing null in Map itself is a mistake. Certain map implementations like ConcurrentHashMap doesn't allow null . Recently, I came
across the thread "map and null values" in lambda mailing list.

http://mail.openjdk.java.net/pipermail/lambda-dev/2013-January/007451.html


I see the discussion was divided. Certainly Doug Lea and Brian Goetz came out against the use of nulls in collections. But it seems that by the end of the thread, a patch was put forward that makes the new default methods on Map null-friendly. I don't think it will really matter that null mappings get skipped in streaming operations. I think it's only in special cases where we care to know the difference between null and missing.

But getting back to the question of which is more confusing, here are some examples of the type of confusion I'm talking about. These are all from the first page of Google results for "java json null value":


That's right: 5 of the top 10 results for "java json null value" are about confusion over this very issue with other JSON APIs that use a special JsonNull type rather than Java null.

As it turns out, there is at least one Java JSON library that implements the idea I'm proposing. The JSON.simple library (I just found it today; was previously unaware of it) uses Java null for JSON null: https://code.google.com/p/json-simple/#Mapping_Between_JSON_and_Java_Entities

If you scroll down that page a bit to "JSON.simple in Projects/Products," it looks like JSON.simple has pretty good adoption in a number of high-profile projects. I think this demonstrates that the suggestion of eschewing JsonValue.NULL isn't completely insane. :)

-Jonathan


[jsr353-experts] Json Null type: friend or foe?

Jonathan Fuerth 01/09/2013

[jsr353-experts] Re: Json Null type: friend or foe?

Jonathan Fuerth 01/14/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Json Null type: friend or foe?

Jitendra Kotamraju 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Json Null type: friend or foe?

Jonathan Fuerth 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Json Null type: friend or foe?

Jonathan Fuerth 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Json Null type: friend or foe?

Jitendra Kotamraju 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?

Jonathan Fuerth 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?

Jitendra Kotamraju 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?

Jonathan Fuerth 01/15/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?

Jonathan Fuerth 01/17/2013

[jsr353-experts] Re: [json-processing-spec users] Re: Re: Re: Re: Re: Json Null type: friend or foe?

Jitendra Kotamraju 01/18/2013
 
 
Close
loading
Please Confirm
Close