Skip to main content

JSON Methodology

The JSON data type produced depends on the Java object type being serialized.

  • Primitives and primitive objects are converted to JSON primitives.
  • Beans and Maps are converted to JSON objects.
  • Collections and arrays are converted to JSON arrays.
  • Anything else is converted to JSON strings.

Data type conversions:​

POJO typeJSON typeExampleSerialized form
StringStringserialize("foobar");'foobar'
NumberNumberserialize(123);123
BooleanBooleanserialize(true);true
NullNullserialize(null);null
Beans with properties of any type on this listObjectserialize(new MyBean());{p1:'val1',p2:true}
Maps with values of any type on this listObjectserialize(new TreeMap());{key1:'val1',key2:true}
Collections and arrays of any type on this listArrayserialize(new Object[]{1,"foo",true});[1,'foo',true]

Date/time types (Calendar, Date, Temporal subtypes, Duration) are serialized natively as ISO 8601 strings. Swaps can be used to convert non-serializable POJOs into serializable forms (such as byte[] arrays to Base-64 encoded strings) or to override the default format for types that already have built-in support.