Skip to main content

[json-processing-spec users] Re: [jsr353-experts] PR status

  • From: David Illsley < >
  • To:
  • Subject: [json-processing-spec users] Re: [jsr353-experts] PR status
  • Date: Sun, 23 Dec 2012 17:41:30 +0000

Hi Jitu,
Good to see the progress. I've just reviewed the javadocs, and have some
personal feedback (apologies if I'm repeating myself):

1. I wasn't paying enough attention when JSON_PROCESSING_SPEC-38 came up
for discussion. I disagree with Mark that "you can just have them throw
UnsupportedOperationException" removes the downside from this change. 

The mutable methods will still appear in IDE autocompletions, and will
likely confuse users who won't see the failure until runtime. I agree
that getValues() might not be obvious, but asMap and asList would be
pretty clear. 

I'm also skeptical that using these intefaces directly will work well
for most people for the reasons pointed out in the Toronto JUG feedback
(or that the lambda support will feel good when used over these
really-generic structures.) 

There could also then be an asList(Class<? extends JsonValue> clazz)
method to provide an easy-to-consume view.

2. Accessing things in a JsonObject still feels trickier than it should
be, and the helper methods don't get us all the way there. There's still
a lot of messing around with null checking which is confusing and error
prone (e.g. the javadoc for JsonObject isn't internally consistent
between getValue and helper methods with regards to null... oh, and
getIntValue can't return a null :)

I'm conscious that you don't want to create a JSON path format. My best
shot at solving this with that constraint is to add:

<T extends JsonValue> T getValueWithDefault(String name, T
defaultValue);

along with a couple of more static values on JsonValue representing
'empty' values:

JsonObject EMPTY_OBJECT
JsonArray EMPTY_ARRAY
JsonString EMPTY_STRING
JsonNumber ZERO

which would allow me to do:
  String token = obj.getValueWithDefault("user", JsonValue.EMTPY_OBJECT)
                               .getValueWithDefault("sessionDetails",
                               JsonValue.EMPTY_OBJECT)
                               .getValueWithDetault("token",
                               JsonValue.EMPTY_STRING)
                               .getValue()

or, even better (but would require a new JsonValueBuilder class to match
the object/array builders): 
  JsonString defaultToken =
  JsonValueBuilder.createJsonString(UUID.randonUUID().toString())
  String token = obj.getValueWithDefault("user", JsonValue.EMTPY_OBJECT)
                               .getValueWithDefault("sessionDetails",
                               JsonValue.EMPTY_OBJECT)
                               .getValueWithDetault("token",
                               defaultToken)
                               .getValue()

Would I add the equivalent to JsonArray? Yes.

HTH. Thoughts?
David

-- 
  David Illsley
  


On Wed, Dec 19, 2012, at 06:51 PM, Jitendra Kotamraju wrote:
> I submitted the PR draft [1] to JCP and also hosted the javadoc [2].
> I will let you know when JCP hosts the draft for review.
> RI artifacts (b02 version) [3] are pushed to maven central.
> 
> Thanks to EG members and user community for contributing towards this 
> milestone.
> We can discuss the remaining issues next week or in new year. Happy 
> holidays !
> 
> Jitu
> 
> [1] 
> http://java.net/projects/json-processing-spec/downloads/download/javax.json-api-1.0-prd-javadoc.jar
> 
> [2] 
> http://json-processing-spec.java.net/nonav/releases/1.0/pr-draft/javadocs/index.html
> 
> [3] http://search.maven.org/#search%7Cga%7C1%7Cjavax.json


[json-processing-spec users] [jsr353-experts] PR status

Jitendra Kotamraju 12/19/2012

[json-processing-spec users] Re: [jsr353-experts] PR status

David Illsley 12/23/2012

[json-processing-spec users] Re: [jsr353-experts] PR status

Jitendra Kotamraju 12/24/2012

[json-processing-spec users] Re: [jsr353-experts] PR status

David Illsley 12/24/2012

[json-processing-spec users] [jsr353-experts] Re: PR status

Jitendra Kotamraju 12/24/2012

[json-processing-spec users] [jsr353-experts] Re: PR status

Werner Keil 12/24/2012
 
 
Close
loading
Please Confirm
Close