Package com.streambase.sb
Class TupleJSONUtil
java.lang.Object
com.streambase.sb.TupleJSONUtil
- All Implemented Interfaces:
JsonUtils
Utilities for dealing with tuples represented in JSON format.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Options for serializing JSON.static class
The Builder class which handles the setting of tuples from JSON Data. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Error message: The format for functions is not a Json objectstatic final String
Error message: JSON functions must have a body or definitionstatic final String
Error message: Unknown JSON attributesstatic final String
Error message: json to tuple field convert errorstatic final String
Error message: json and tuple field number mismatchstatic final String
Error message: timestamp parse errorstatic final String
Error message: json to tuple convert error, unknown JSON attributesstatic final String
Error message: Unrecognized json value errorstatic final String
Error message: "PREFER_LIST and PREFER_MAP are mutually exclusiveFields inherited from interface com.streambase.sb.JsonUtils
JSON_KEY_ARGUMENT_SCHEMA, JSON_KEY_BODY, JSON_KEY_CAPTURED_SCHEMA, JSON_KEY_ELEMENT_TYPE, JSON_KEY_ENVIRONMENT, JSON_KEY_ENVIRONMENT_SCHEMA, JSON_KEY_FIELDS, JSON_KEY_FUNCTION_DEFINITION, JSON_KEY_IN_TRANSFORMER, JSON_KEY_INNER, JSON_KEY_INNER_TYPE, JSON_KEY_INPUT, JSON_KEY_NAME, JSON_KEY_OPTIONS, JSON_KEY_OUT_TRANSFORMER, JSON_KEY_OUTPUT, JSON_KEY_RETURN_TYPE, JSON_KEY_SCHEMA, JSON_KEY_TYPE, JSON_KEY_TYPE_NAME, JSON_KEY_VALUE, JSON_VALUE_INFINITY, JSON_VALUE_MINUS_INFINITY, JSON_VALUE_NAN
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
fieldObjectToJsonString
(Schema.Field f, Object value, EnumSet<TupleJSONUtil.Options> options) static String
fieldObjectToJsonString
(Schema.Field f, Object value, EnumSet<TupleJSONUtil.Options> options, String timestampFormat) static String
Return the string representation of objects extracted from json according to pathstatic com.fasterxml.jackson.databind.ObjectMapper
static com.fasterxml.jackson.databind.JsonNode
parseJSONString
(String json) Parse JSON string into a JSON objectstatic com.fasterxml.jackson.databind.JsonNode
Parse JSON string into a JSON objectstatic void
Deprecated.static void
Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTuple
(Tuple tuple, Object jsonObject, boolean strict, String timestampFormat, boolean numericTimestampsAsInterval) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTupleFromJSON
(Tuple tuple, String JSONString) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTupleFromJSON
(Tuple tuple, String JSONString, String timestampFormat) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTupleFromJSON
(Tuple tuple, String JSONString, String timestampFormat, boolean numericTimestampsAsInterval) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTupleFromJSONLoose
(Tuple tuple, String JSONString) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTupleFromJSONLoose
(Tuple tuple, String JSONString, String timestampFormat) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic void
setTupleFromJSONLoose
(Tuple tuple, String JSONString, String timestampFormat, boolean numericTimestampsAsInterval) Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitystatic 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
(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.static String
toJSONString
(Collection<Tuple> tuples) static String
typeObjectToJsonString
(CompleteDataType cdt, Object value, EnumSet<TupleJSONUtil.Options> options) static String
typeObjectToJsonString
(CompleteDataType cdt, Object value, EnumSet<TupleJSONUtil.Options> options, String timestampFormat)
-
Field Details
-
JSON_TO_TUPLE_FIELD_CONVERT_ERROR
Error message: json to tuple field convert error- See Also:
-
JSON_TO_TUPLE_UNRECOGNIZED_FIELD_VALUE_ERROR
Error message: Unrecognized json value error- See Also:
-
JSON_TO_TUPLE_UNRECOGNIZED_FIELD_ERROR
Error message: json to tuple convert error, unknown JSON attributes- See Also:
-
JSON_TO_TUPLE_SCHEMA_MISMATCH_ERROR
Error message: json and tuple field number mismatch- See Also:
-
JSON_TO_TUPLE_TIMESTAMP_PARSE_ERROR
Error message: timestamp parse error- See Also:
-
JSON_TO_FUNCTION_FORMAT_ERROR
Error message: The format for functions is not a Json object- See Also:
-
JSON_TO_FUNCTION_MISSING_BODY_OR_DEFINITION_ERROR
Error message: JSON functions must have a body or definition- See Also:
-
JSON_TO_FUNCTION_UNKNOWN_ATTRIBUTES_ERROR
Error message: Unknown JSON attributes- See Also:
-
TO_JSON_OPTIONS_ERROR
Error message: "PREFER_LIST and PREFER_MAP are mutually exclusive- See Also:
-
-
Method Details
-
newObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()- Returns:
- A new object mapper, configured
-
jsonPath
Return the string representation of objects extracted from json according to pathSee https://github.com/json-path/JsonPath for full documentation.
- Parameters:
json
- string representation of json to parsejsonPath
- 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)
-
fieldObjectToJsonString
public static String fieldObjectToJsonString(Schema.Field f, Object value, EnumSet<TupleJSONUtil.Options> options) throws StreamBaseException - Parameters:
f
- fieldvalue
- field valueoptions
- parse options- Returns:
- a JSON string
- Throws:
StreamBaseException
- error in convert tuple to json string
-
fieldObjectToJsonString
public static String fieldObjectToJsonString(Schema.Field f, Object value, EnumSet<TupleJSONUtil.Options> options, String timestampFormat) throws StreamBaseException - Parameters:
f
- fieldvalue
- field valueoptions
- parse optionstimestampFormat
- timestamp format- Returns:
- a JSON string
- Throws:
StreamBaseException
- error in convert tuple to json string
-
typeObjectToJsonString
public static String typeObjectToJsonString(CompleteDataType cdt, Object value, EnumSet<TupleJSONUtil.Options> options) throws StreamBaseException - Parameters:
cdt
- a complete data typevalue
- field valueoptions
- parse options- Returns:
- JSON string for complete data type
- Throws:
StreamBaseException
- error in convert data type to json string
-
typeObjectToJsonString
public static String typeObjectToJsonString(CompleteDataType cdt, Object value, EnumSet<TupleJSONUtil.Options> options, String timestampFormat) throws StreamBaseException - Parameters:
cdt
- a complete data typevalue
- Data type valueoptions
- Conversion optionstimestampFormat
- Timestamp format- Returns:
- JSON string for complete data type
- Throws:
StreamBaseException
- Conversion error
-
setTuple
@Deprecated public static void setTuple(Tuple tuple, Object jsonObject, boolean strict) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet the fields of a tuple based on the contents of a JSON object- Parameters:
tuple
- the tuple to setjsonObject
- the JSON object; must have at least the fields of the tuple's schemastrict
- whether to throw an exception when fields are missing from tuple's schema- Throws:
StreamBaseException
- Conversion error
-
setTuple
@Deprecated public static void setTuple(Tuple tuple, Object jsonObject, boolean strict, String timestampFormat) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet the fields of a tuple based on the contents of a JSON object- Parameters:
tuple
- the tuple to setjsonObject
- the JSON object; must have at least the fields of the tuple's schemastrict
- whether to throw an exception when fields are missing from tuple's schematimestampFormat
- the timestamp format to use when converting- Throws:
StreamBaseException
- Conversion error
-
setTuple
@Deprecated public static void setTuple(Tuple tuple, Object jsonObject, boolean strict, String timestampFormat, boolean numericTimestampsAsInterval) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet the fields of a tuple based on the contents of a JSON object- Parameters:
tuple
- the tuple to setjsonObject
- the JSON object; must have at least the fields of the tuple's schemastrict
- whether to throw an exception when fields are missing from tuple's schematimestampFormat
- the timestamp format to use when convertingnumericTimestampsAsInterval
- If true any numeric values in a timestamp field will be converted to interval types, if false they are considered a timestamp- Throws:
StreamBaseException
- error initializing tuple from JSON
-
setTupleFromJSON
@Deprecated public static void setTupleFromJSON(Tuple tuple, String JSONString) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet the fields of a tuple based on the contents of a JSON string- Parameters:
tuple
- the tuple to setJSONString
- the JSON string; must have at least the fields of the tuple's schema- Throws:
StreamBaseException
- conversion to tuple error
-
setTupleFromJSON
@Deprecated public static void setTupleFromJSON(Tuple tuple, String JSONString, String timestampFormat) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet the fields of a tuple based on the contents of a JSON string- Parameters:
tuple
- the tuple to setJSONString
- the JSON string; must have at least the fields of the tuple's schematimestampFormat
- the timestamp format to use when converting- Throws:
StreamBaseException
- conversion to tuple error
-
setTupleFromJSON
@Deprecated public static void setTupleFromJSON(Tuple tuple, String JSONString, String timestampFormat, boolean numericTimestampsAsInterval) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet the fields of a tuple based on the contents of a JSON string- Parameters:
tuple
- the tuple to setJSONString
- the JSON string; must have at least the fields of the tuple's schematimestampFormat
- the timestamp format to use when convertingnumericTimestampsAsInterval
- If true any numeric values in a timestamp field will be converted to interval types, if false they are considered a timestamp- Throws:
StreamBaseException
- conversion to tuple error
-
setTupleFromJSONLoose
@Deprecated public static void setTupleFromJSONLoose(Tuple tuple, String JSONString) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet 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
- the tuple to setJSONString
- the JSON string; must have at least the fields of the tuple's schema- Throws:
StreamBaseException
- conversion to tuple error
-
setTupleFromJSONLoose
@Deprecated public static void setTupleFromJSONLoose(Tuple tuple, String JSONString, String timestampFormat) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet 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
- the tuple to setJSONString
- the JSON string; must have at least the fields of the tuple's schematimestampFormat
- timestamp format- Throws:
StreamBaseException
- conversion to tuple error
-
setTupleFromJSONLoose
@Deprecated public static void setTupleFromJSONLoose(Tuple tuple, String JSONString, String timestampFormat, boolean numericTimestampsAsInterval) throws StreamBaseException Deprecated.Use theTupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionalitySet 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
- the tuple to setJSONString
- the JSON string; must have at least the fields of the tuple's schematimestampFormat
- timestamp formatnumericTimestampsAsInterval
- If true any numeric values in a timestamp field will be converted to interval types, if false they are considered a timestamp- Throws:
StreamBaseException
- conversion to tuple error
-
parseJSONString
public static com.fasterxml.jackson.databind.JsonNode parseJSONString(String json) throws StreamBaseException Parse JSON string into a JSON object- Parameters:
json
- json to parse- Returns:
- a object from JSON
- Throws:
StreamBaseException
- parse error
-
parseJSONStringWithoutThrowsException
public static com.fasterxml.jackson.databind.JsonNode parseJSONStringWithoutThrowsException(String json) Parse JSON string into a JSON object- Parameters:
json
- json to parse- Returns:
- a object from JSON
-
toJSONString
Convert a tuple to its JSON representation.- Parameters:
t
- The tuple to serializeoptions
- The serialization optionsTupleJSONUtil.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 serializeoptions
- The serialization optionsTupleJSONUtil.Options
timestampFormat
- the timestamp format to use when converting- Returns:
- the JSON string
-
toJSONMapString
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 serializetimeStampFormat
- the timestamp format to use when converting- Returns:
- the JSON string
-
toJSONMapString
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
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 serializetimeStampFormat
- the timestamp format to use when converting- Returns:
- the JSON string
-
toJSONListString
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
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
-
toJSONString
- Parameters:
tuples
- the tuples to convert to JSON- Returns:
- a string of JSON representing an array of tuples
-
TupleJSONUtil.SetTupleFromJSON
Builder and its .process() to handle this functionality