Issue Details (XML | Word | Printable)

Key: JSON_PROCESSING_SPEC-40
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: jitu
Reporter: jhorstmann
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
json-processing-spec

JsonBuilder and JsonReader should be interfaces

Created: 11/Dec/12 08:09 PM   Updated: 04/Feb/13 05:46 AM   Resolved: 04/Feb/13 05:46 AM
Component/s: None
Affects Version/s: 1.0-pr
Fix Version/s: 1.0-pfd

Time Tracking:
Not Specified

Tags:
Participants: jhorstmann, jitu and wenshao


 Description  « Hide

The current design limits possible performance improvements that could be obtained by custom parser implementations. A cleaner design would let the implementation provide both parser and object model implementations that are better integrated and higher performing.

If we implement http://java.net/jira/browse/JSON_PROCESSING_SPEC-9 a json structure could consist of a mix between implementations from the api package and implementation defined classes.

Builders would be created by static methods of the Json class or a JsonBuilderFactory created via the Json class.
JsonReader would require a JsonReaderFactory with similar methods to JsonParserFactory.

Discussion at http://java.net/projects/json-processing-spec/lists/users/archive/2012-12/message/9 and http://java.net/projects/json-processing-spec/lists/users/archive/2012-12/message/54



jitu added a comment - 12/Dec/12 12:26 AM

Since JsonParser/JsonGenerator are already used by JsonReader/JsonGenerator, most of the performance improvements are available from a provider. Perhpas, the remaining improvements for JsonString/JsonNumber impl may not be much.

The high-level API should more usable than the low-level API, i.e new JsonArrayBuilder() etc is more user friendly.

Otherwise, a possible approach is to introduce
JsonReaderFactory, JsonWriterFactory, JsonBuilderFactory, and all possible methods on Json. That seem bit heavy-weight to me and not justify the performance benefits.


wenshao added a comment - 13/Dec/12 03:23 AM

i can not understand why not be interfaces?

not just these two, should be interfaces include following:
JsonReader
JsonWriter
JsonArrayBuilder
JsonObjectBuilder


jhorstmann added a comment - 07/Jan/13 11:01 AM

The current design, with only JsonParser as an implementation provided class, also seems to have performance problems of its own due to repeated ServiceLoader lookup. With JsonReader as an interface and a threadsafe JsonReaderFactory these lookups can be avoided.

Discussion at http://java.net/projects/json-processing-spec/lists/users/archive/2013-01/message/2


jitu added a comment - 09/Jan/13 08:01 PM

One suggestion was to cache the provider so that there won't be service lookup costs for each JsonReader/JsonWriter. The cache strategy that is suggested is:
"The cache should be a ThreadLocal, and the cached value should include
a reference to the class loader that was used to look up the provider,
presumably the thread-context class loader. Use the cached provider only
when the saved class loader matches the one that you'd use if you were
going to look it up again."


jitu added a comment - 04/Feb/13 05:46 AM

Made JsonReader, JsonWriter, JsonArrayWriter, JsonObjectWriter as interfaces.
Added JsonReaderFactor, JsonWriterFactory, JsonBuilderFactory interfaces to create these objects.

Added methods to create these objects as well as the factory classes.