Contexts, Builders, Sessions, and PropertyStores
All the serializers, parsers, and REST server/client classes use the following design pattern:
BeanContext
, JsonSerializer
Context
objects.
BeanSession
, JsonSerializerSession
Sessions
but lighter than Contexts
.
Context
contains one PropertyStore
that defines all the configuration about that object.
For example, the class hierarchy for JsonSerializer
is:
Object
Each context object in the hierarchy define properties that can be stored in a PropertyStore
such as
The class hierarchy for JsonSerializerBuilder
is:
Object
The class hierarchy for JsonSerializerSession
is:
Object
The general idea behind a {@link oaj.PropertyStore} is to serve as a reusable configuration of an artifact (such as a serializer) such that the artifact can be cached and reused if the property stores are 'equal'.
For example, two serializers of the same type created with the same configuration will always end up being the same serializer:
This has the effect of significantly improving performance especially if you're creating many serializers and parsers.
The {@link oaj.PropertyStoreBuilder} class is used to build up and instantiate immutable
PropertyStore
objects.
In the example above, the property store being built looks like the following:
PropertyStore ps = PropertyStore
.
Property stores are immutable, comparable, and their hashcodes are calculated exactly one time. That makes them particularly suited for use as hashmap keys, and thus for caching reusable serializers and parsers.
Refer to the {@link oaj.PropertyStore} javadoc for a detailed explaination on how property stores work.