Class JsonPathEntryConverter
java.lang.Object
de.xima.fc.converter.json.JsonPathEntryConverter
Converts between a JSON object and a list of entries, where each entry represents a primitive value in the JSON
object.
Each entry has a path, an index, a type, and a value. The path is a dot-separated list of property names; array indices are represented as a star. The index is a comma-separated list of array indices. The type is a string representing the type name (e.g. 'boolean' or 'long'). The value is a string representation of the primitive value.
Empty property names are represented as an underscore. Periods in a path part are encoded as \.,
stars as \*, underscores as \_. Backslashes are encoded as \\.
Example:
{"": 0, foo: { bar: "1", baz: [2, 3.5, {qux: true, [null]} ] } }
converts to:
[
{path: "_", index: "", type: INTEGER, value: "0"},
{path: "foo.bar", index: "", type: STRING, value: "1"},
{path: "foo.baz.", index: "0", type: LONG, value: "2"},
{path: "foo.baz.", index: "1", type: DOUBLE, value: "3.5"},
{path: "foo.baz..qux", index: "2", type: BOOLEAN, value: "true"}
{path: "foo.baz.*.qux.*", index: "2,0", type: NULL, value: ""}
]
- Since:
- 8.2.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a builder for configuring aJsonPathEntryConverter.convertToFlat(Object json, IJsonIterator jsonIterator) Converts a map to a list of entries, with one entry for each primitive value in the map.convertToJson(List<JsonPathEntry> entries, IJsonBuilder<?, ?> jsonBuilder) Converts a list of entries, as created byconvertToFlat(Object, IJsonIterator), to a JSON value.<A> AconvertToJsonArray(List<JsonPathEntry> entries, IJsonBuilder<A, ?> jsonBuilder) Converts a list of entries, as created byconvertToFlat(Object, IJsonIterator), to a JSON array.<O> OconvertToJsonObject(List<JsonPathEntry> entries, IJsonBuilder<?, O> jsonBuilder) Converts a list of entries, as created byconvertToFlat(Object, IJsonIterator), to a JSON object.
-
Method Details
-
convertToFlat
Converts a map to a list of entries, with one entry for each primitive value in the map.- Parameters:
json- Map to convert.jsonIterator- Iterator for iterating over JSON elements.- Returns:
- List of entries.
-
convertToJson
Converts a list of entries, as created byconvertToFlat(Object, IJsonIterator), to a JSON value.- Parameters:
entries- Entries to convert.jsonBuilder- Builder for creating JSON values.- Returns:
- Converted JSON value.
-
convertToJsonArray
Converts a list of entries, as created byconvertToFlat(Object, IJsonIterator), to a JSON array. When the value represented by the entries is not an array, returns an empty array.- Type Parameters:
A- Type of the JSON array.- Parameters:
entries- Entries to convert.jsonBuilder- Builder for creating JSON values.- Returns:
- Converted JSON array.
-
convertToJsonObject
Converts a list of entries, as created byconvertToFlat(Object, IJsonIterator), to a JSON object. When the value represented by the entries is not an object, returns an empty object.- Type Parameters:
O- Type of the JSON object.- Parameters:
entries- Entries to convert.jsonBuilder- Builder for creating JSON values.- Returns:
- Converted JSON object.
-
builder
Creates a builder for configuring aJsonPathEntryConverter.- Returns:
- Builder for configuring a
JsonPathEntryConverter.
-