Generic JSON encoder using jakarta.json API.
This supports the standard types Boolean, Number, Character, CharSequence,
Date, LocalDate and Instant. If the given object type does not match any of them, then it
will attempt to inspect the object as a JavaBean using the Introspector, whereby the public properties
(public getters) will be encoded as a JS object. It also supports arrays, Collections and Maps of
them, even nested ones. The dates are formatted as ISO8601 instant via DateTimeFormatter#ISO_INSTANT, so you
can if necessary just pass the value straight to new Date(value) in JavaScript.
Below encoding options are available:
Option#SKIP_NULL_VALUES: skip null values in arrays, collections, maps and beans. This may reduce an
unnecessarily bloated JSON object.
Option#USE_RFC1123_DATE: format dates as RFC1123 via DateTimeFormatter#RFC_1123_DATE_TIME. This
may improve compatibility with older web browsers.
| Modifier and Type | Class and Description |
|---|---|
| public static enum |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static String | |
| public static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | encodeCollection(String name, Collection<?> collection, JsonGenerator generator, EnumSet<Json.
|
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| private static void |
| ERROR_INVALID_BEAN | back to summary |
|---|---|
| private static final String ERROR_INVALID_BEAN | |
| ERROR_INVALID_GETTER | back to summary |
|---|---|
| private static final String ERROR_INVALID_GETTER | |
| Json | back to summary |
|---|---|
| public Json() | |
| encode | back to summary |
|---|---|
| public static String encode(Object object, Json. Encodes the given object as JSON and returns a string in JSON format. The encoded object will be available as
| |
| encode | back to summary |
|---|---|
| public static void encode(Object object, Writer writer, Json. Encodes the given object as JSON while streaming the string in JSON format to the given writer. The encoded object
will be available as
| |
| encode | back to summary |
|---|---|
| private static void encode(String name, Object object, JsonGenerator generator, EnumSet<Json. | |
| encodeArray | back to summary |
|---|---|
| private static void encodeArray(String name, Object array, JsonGenerator generator, EnumSet<Json. | |
| encodeBean | back to summary |
|---|---|
| private static void encodeBean(String name, Object bean, JsonGenerator generator, EnumSet<Json. | |
| encodeBigDecimal | back to summary |
|---|---|
| private static void encodeBigDecimal(String name, BigDecimal value, JsonGenerator generator) | |
| encodeBigInteger | back to summary |
|---|---|
| private static void encodeBigInteger(String name, BigInteger value, JsonGenerator generator) | |
| encodeBoolean | back to summary |
|---|---|
| private static void encodeBoolean(String name, Boolean value, JsonGenerator generator) | |
| encodeCollection | back to summary |
|---|---|
| private static void encodeCollection(String name, Collection<?> collection, JsonGenerator generator, EnumSet<Json. | |
| encodeDouble | back to summary |
|---|---|
| private static void encodeDouble(String name, double value, JsonGenerator generator) | |
| encodeInstant | back to summary |
|---|---|
| private static void encodeInstant(String name, Instant value, JsonGenerator generator, EnumSet<Json. | |
| encodeInteger | back to summary |
|---|---|
| private static void encodeInteger(String name, int value, JsonGenerator generator) | |
| encodeLong | back to summary |
|---|---|
| private static void encodeLong(String name, long value, JsonGenerator generator) | |
| encodeMap | back to summary |
|---|---|
| private static void encodeMap(String name, Map<?, ?> map, JsonGenerator generator, EnumSet<Json. | |
| encodeNull | back to summary |
|---|---|
| private static void encodeNull(String name, JsonGenerator generator) | |
| encodeString | back to summary |
|---|---|
| private static void encodeString(String name, String value, JsonGenerator generator) | |
| Modifier and Type | Field and Description |
|---|---|
| public static final Json. | SKIP_NULL_VALUES
Skip null values in arrays, collections, maps and beans. |
| public static final Json. | USE_RFC1123_DATE
Format dates as RFC1123 via |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Json. | |
| public static Json. |
| SKIP_NULL_VALUES | back to summary |
|---|---|
| public static final Json. Skip null values in arrays, collections, maps and beans. This may reduce an unnecessarily bloated JSON object. | |
| USE_RFC1123_DATE | back to summary |
|---|---|
| public static final Json. Format dates as RFC1123 via | |
| Option | back to summary |
|---|---|
| private Option() | |
| valueOf | back to summary |
|---|---|
| public static Json. | |
| values | back to summary |
|---|---|
| public static Json. | |