Class JsonPathEntryConverter


  • public final class JsonPathEntryConverter
    extends Object
    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:

     {foo: {"", 0, 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
    • Method Detail

      • convertToFlat

        public List<JsonPathEntry> convertToFlat​(Object json,
                                                 IJsonIterator jsonIterator)
        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.
      • convertToJsonArray

        public <A> A convertToJsonArray​(List<JsonPathEntry> entries,
                                        IJsonBuilder<A,​?> jsonBuilder)
        Converts a list of entries, as created by convertToFlat(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

        public <O> O convertToJsonObject​(List<JsonPathEntry> entries,
                                         IJsonBuilder<?,​O> jsonBuilder)
        Converts a list of entries, as created by convertToFlat(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.