com.streambase.sb

## Class TupleJSONUtil

- java.lang.Object
- - com.streambase.sb.TupleJSONUtil

-     public final class TupleJSONUtil
      extends Object

  Utilities for dealing with tuples represented in JSON format.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TupleJSONUtil.Options` Options for serializing JSON.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `jsonPath(String json, String jsonPath)` Return the string representation of objects extracted from json according to path
    `static void` | `setTuple(Tuple tuple, Object jsonObject, boolean strict)` Set the fields of a tuple based on the contents of a JSON object
    `static void` | `setTuple(Tuple tuple, Object jsonObject, boolean strict, String timestampFormat)` Set the fields of a tuple based on the contents of a JSON object
    `static void` | `setTuple(Tuple tuple, Object jsonObject, boolean strict, String timestampFormat, boolean numericTimestampsAsInterval)` Set the fields of a tuple based on the contents of a JSON object
    `static void` | `setTupleFromJSON(Tuple tuple, String JSONString)` Set the fields of a tuple based on the contents of a JSON string
    `static void` | `setTupleFromJSON(Tuple tuple, String JSONString, String timestampFormat)` Set the fields of a tuple based on the contents of a JSON string
    `static void` | `setTupleFromJSON(Tuple tuple, String JSONString, String timestampFormat, boolean numericTimestampsAsInterval)` Set the fields of a tuple based on the contents of a JSON string
    `static void` | `setTupleFromJSONLoose(Tuple tuple, String JSONString)` Set the fields of a tuple based on the contents of a JSON string.
    `static void` | `setTupleFromJSONLoose(Tuple tuple, String JSONString, String timestampFormat)` Set the fields of a tuple based on the contents of a JSON string.
    `static void` | `setTupleFromJSONLoose(Tuple tuple, String JSONString, String timestampFormat, boolean numericTimestampsAsInterval)` Set the fields of a tuple based on the contents of a JSON string.
    `static String` | `toJSONListString(Tuple tuple)` Return the JSON string representation of the supplied tuple.
    `static String` | `toJSONListString(Tuple tuple, String timeStampFormat)` Return the JSON string representation of the supplied tuple.
    `static String` | `toJSONMapString(Tuple tuple)` Return the JSON string representation of the supplied tuple.
    `static String` | `toJSONMapString(Tuple tuple, String timeStampFormat)` Return the JSON string representation of the supplied tuple.
    `static String` | `toJSONMapStringSingleQuote(Tuple tuple)` Return the single quote JSON string representation of the supplied tuple.
    `static String` | `toJSONString(Collection<Tuple> tuples)`
    `static String` | `toJSONString(Tuple t, EnumSet<TupleJSONUtil.Options> options)` Convert a tuple to its JSON representation.
    `static String` | `toJSONString(Tuple t, EnumSet<TupleJSONUtil.Options> options, String timestampFormat)` Convert a tuple to its JSON representation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### setTuple

          public static void setTuple(Tuple tuple,
                                      Object jsonObject,
                                      boolean strict)
                               throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON object
      Parameters:
        `tuple` - the tuple to set
        `jsonObject` - the JSON object; must have at least the fields of the tuple's schema
        `strict` - whether to throw an exception when fields are missing from tuple's schema
      Throws:
        `com.alibaba.fastjson.JSONException`
        `StreamBaseException`

    - #### setTuple

          public static void setTuple(Tuple tuple,
                                      Object jsonObject,
                                      boolean strict,
                                      String timestampFormat)
                               throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON object
      Parameters:
        `tuple` - the tuple to set
        `jsonObject` - the JSON object; must have at least the fields of the tuple's schema
        `strict` - whether to throw an exception when fields are missing from tuple's schema
        `timestampFormat` - the timestamp format to use when converting
      Throws:
        `com.alibaba.fastjson.JSONException`
        `StreamBaseException`

    - #### setTuple

          public static void setTuple(Tuple tuple,
                                      Object jsonObject,
                                      boolean strict,
                                      String timestampFormat,
                                      boolean numericTimestampsAsInterval)
                               throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON object
      Parameters:
        `tuple` - the tuple to set
        `jsonObject` - the JSON object; must have at least the fields of the tuple's schema
        `strict` - whether to throw an exception when fields are missing from tuple's schema
        `timestampFormat` - the timestamp format to use when converting
        `numericTimestampsAsInterval` - If true any numeric values in a timestamp field will be converted to interval types, if false they are considered timestamp
      Throws:
        `com.alibaba.fastjson.JSONException`
        `StreamBaseException`

    - #### setTupleFromJSON

          public static void setTupleFromJSON(Tuple tuple,
                                              String JSONString)
                                       throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON string
      Parameters:
        `tuple` - the tuple to set
        `JSONString` - the JSON string; must have at least the fields of the tuple's schema
      Throws:
        `com.alibaba.fastjson.JSONException`
        `StreamBaseException`

    - #### setTupleFromJSON

          public static void setTupleFromJSON(Tuple tuple,
                                              String JSONString,
                                              String timestampFormat)
                                       throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON string
      Parameters:
        `tuple` - the tuple to set
        `JSONString` - the JSON string; must have at least the fields of the tuple's schema
        `timestampFormat` - the timestamp format to use when converting
      Throws:
        `com.alibaba.fastjson.JSONException`
        `StreamBaseException`

    - #### setTupleFromJSON

          public static void setTupleFromJSON(Tuple tuple,
                                              String JSONString,
                                              String timestampFormat,
                                              boolean numericTimestampsAsInterval)
                                       throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON string
      Parameters:
        `tuple` - the tuple to set
        `JSONString` - the JSON string; must have at least the fields of the tuple's schema
        `timestampFormat` - the timestamp format to use when converting
        `numericTimestampsAsInterval` - If true any numeric values in a timestamp field will be converted to interval types, if false they are considered timestamp
      Throws:
        `com.alibaba.fastjson.JSONException`
        `StreamBaseException`

    - #### setTupleFromJSONLoose

          public static void setTupleFromJSONLoose(Tuple tuple,
                                                   String JSONString)
                                            throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON string. If the JSON string does not have enough fields as specified in the tuple, these will just be populated with nulls.
      Parameters:
        `tuple` -
        `JSONString` -
      Throws:
        `StreamBaseException`

    - #### setTupleFromJSONLoose

          public static void setTupleFromJSONLoose(Tuple tuple,
                                                   String JSONString,
                                                   String timestampFormat)
                                            throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON string. If the JSON string does not have enough fields as specified in the tuple, these will just be populated with nulls.
      Parameters:
        `tuple` -
        `JSONString` -
        `timestampFormat` -
      Throws:
        `StreamBaseException`

    - #### setTupleFromJSONLoose

          public static void setTupleFromJSONLoose(Tuple tuple,
                                                   String JSONString,
                                                   String timestampFormat,
                                                   boolean numericTimestampsAsInterval)
                                            throws StreamBaseException

      Set the fields of a tuple based on the contents of a JSON string. If the JSON string does not have enough fields as specified in the tuple, these will just be populated with nulls.
      Parameters:
        `tuple` -
        `JSONString` -
        `timestampFormat` -
        `numericTimestampsAsInterval` - If true any numeric values in a timestamp field will be converted to interval types, if false they are considered timestamp
      Throws:
        `StreamBaseException`

    - #### toJSONString

          public static String toJSONString(Tuple t,
                                            EnumSet<TupleJSONUtil.Options> options)

      Convert a tuple to its JSON representation.
      Parameters:
        `t` - The tuple to serialize
        `options` - The serialization options `TupleJSONUtil.Options`
      Returns:
        the JSON string

    - #### toJSONString

          public static String toJSONString(Tuple t,
                                            EnumSet<TupleJSONUtil.Options> options,
                                            String timestampFormat)

      Convert a tuple to its JSON representation.
      Parameters:
        `t` - The tuple to serialize
        `options` - The serialization options `TupleJSONUtil.Options`
        `timestampFormat` - the timestamp format to use when converting
      Returns:
        the JSON string

    - #### toJSONMapString

          public static String toJSONMapString(Tuple tuple,
                                               String timeStampFormat)

      Return the JSON string representation of the supplied tuple. Prefer maps to lists for expressing hierarchy. If tuple includes timestamp, format it based on timeStampFormat.
      Parameters:
        `tuple` - The tuple to serialize
        `timeStampFormat` - the timestamp format to use when converting
      Returns:
        the JSON string

    - #### toJSONMapString

          public static String toJSONMapString(Tuple tuple)

      Return the JSON string representation of the supplied tuple. Prefer maps to lists for expressing hierarchy.
      Parameters:
        `tuple` - The tuple to serialize
      Returns:
        the JSON string

    - #### toJSONListString

          public static String toJSONListString(Tuple tuple,
                                                String timeStampFormat)

      Return the JSON string representation of the supplied tuple. Prefer lists to maps for expressing hierarchy. If tuple includes timestamp, format it based on timeStampFormat.
      Parameters:
        `tuple` - The tuple to serialize
        `timeStampFormat` - the timestamp format to use when converting
      Returns:
        the JSON string

    - #### toJSONListString

          public static String toJSONListString(Tuple tuple)

      Return the JSON string representation of the supplied tuple. Prefer lists to maps for expressing hierarchy.
      Parameters:
        `tuple` - The tuple to serialize
      Returns:
        the JSON string

    - #### toJSONMapStringSingleQuote

          public static String toJSONMapStringSingleQuote(Tuple tuple)

      Return the single quote JSON string representation of the supplied tuple. Prefer maps to lists for expressing hierarchy.
      Parameters:
        `tuple` - The tuple to serialize
      Returns:
        the JSON string

    - #### jsonPath

          public static String jsonPath(String json,
                                        String jsonPath)

      Return the string representation of objects extracted from json according to path

      See http://code.google.com/p/json-path/ for full documentation.

      Parameters:
        `json` - string representation of json to parse
        `jsonPath` - string path to traverse to extract objects out of json
      Returns:
        string representation of list of extracted json results; always returns results as a list (which is then stringified)

    - #### toJSONString

          public static String toJSONString(Collection<Tuple> tuples)

      Parameters:
        `tuples` - the tuples to convert to JSON
      Returns:
        a string of JSON representing an array of tuples

Copyright © 2015–2018 Cloud Software Group, Inc.. All rights reserved.