Creation and Thread-Safety #54
falkreon
announced in
Design Goals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Right now, the start of any Jankson interaction is
Jankson.builder().build()
, often completely uncustomized.Good:
Bad:
There are two proposals really that could move us in the right direction.
Option 1: Incremental improvement
Option 2: Redesign
Instead of opening json with a Jankson, open a json with a JsonReader (think ZipInputStream). This better communicates the single-use / threaded nature of the object, and gives us a really nice middle ground for interacting with either the document API, semantic objects, or both.
Creating the JsonReader presents some design challenges, since the Reader needs access to a whole marshaller and all those other nice builder settings. So we could make them an optional constructor argument:
new JsonReader(new FileReader(foo))
versusnew JsonReader(new FileReader(foo), settings)
.Specifically,
settings
could be a DeserializerSettings set up with only those related to unpacking json, not writing it, because...you could write json with a JsonWriter. Same constructor flow, with an optional SerializerSettings.
Then we could provide bigger concepts like some kind of threadsafe dispatcher to spin off readers and writers with related settings.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions