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]

In addition, swaps can be used to convert non-serializable POJOs into serializable forms, such as converting Calendar object to ISO8601 strings, or byte[] arrays to Base-64 encoded strings.