-
Notifications
You must be signed in to change notification settings - Fork 1
JOM API
The JOM("JSON Object Model") is defined from four key interfaces:
-
JSONNode
- This is the tagging base interface that JSON Object and JSON Array classes inherit from -
JSONObject
- Represents a JSON object (data wrapped in{
and}
in JSON notation) -
JSONArray
- Represents a JSON array (data wrapped in[
and]
in JSON notation) -
JSONValue<T>
- Represents a value contained in eitherJSONObject
orJSONArray
. The generic interface allows for any value to be represented.
The JSONObject
and JSONArray
interfaces include numerous setter and getter methods that allow you to create JSON objects easily.
Pulling these together are a set of Factory classes. These classes contain static members that allow you to quickly and easily create instances of these interfaces. The are two main Factory classes in the JOM implementation:
-
JSONFactory
- This is the entry point for creating JSON objects and Parsers -
NodeFactory
- contains methods that allow you to create concrete implementationsJSONObject
,JSONArray
and variousJSONValue
instances. There are other helper methods that will processjava.util.List
andjava.util.Map
instances into JSON. Likewise there are methods that will convertjava.lang.Object
instances into values recognized by the JOM.
A side note: All of these interfaces are backed by package private implementations. I admit that I was being too clever by half initially when I depended on properties to define the implementation and Classloaders to instantiate the classes. While it provided the greatest flexibility for defining the implementation of these interfaces, it has an unintended side effect of increasing load speeds by roughly 2X. For large data, this is a significant performance hit. Now, the NodeFactory in particular just instantiates the class hardcoded to it.