Skip to content

JOM API

xmljim edited this page Feb 6, 2018 · 2 revisions

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 either JSONObject or JSONArray. 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 implementations JSONObject, JSONArray and various JSONValue instances. There are other helper methods that will process java.util.List and java.util.Map instances into JSON. Likewise there are methods that will convert java.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.

Clone this wiki locally