com.ibm.streams.operator.encoding
Interface JSONEncoding<O extends java.util.Map,A extends java.util.List>
-
- Type Parameters:
O
- Class representing a JSON objectA
- Class representing a JSON array
public interface JSONEncoding<O extends java.util.Map,A extends java.util.List>
Interface to encode Tuples into JSON (JavaScript Object Notation) data structures.Type mapping to JSON representation Type.MetaType
JSON type BOOLEAN
true|false
INT8
,INT16
,INT32
,INT64
,FLOAT32
,FLOAT64
,DECIMAL32
,DECIMAL64
,DECIMAL128
number UINT8
,UINT16
,UINT32
,UINT64
number (as the unsigned value) RSTRING
,USTRING
,BSTRING
string TIMESTAMP
number (from Timestamp.getTimeAsSeconds()
)ENUM
string TUPLE
object MAP
,BMAP
object LIST
,BLIST
SET
,BSET
array BLOB
,XML
,COMPLEX32
,COMPLEX64
not supported getAttributeObject(Tuple, Attribute)
.
For any SPLmap
the key type must be convertible to aString
and the value type convertible to a JSON value. The value type is mapped according to the mapping table above.
For any SPLlist
orset
type the elements of the JSON array follow the mapping table above for the SPL element type.The interface interfaces with JSON libraries where the classes that represent JSON objects and arrays implement
java.util.Map
andjava.util.List
respectively, such as JSON4J and json-simple. A library specific instance is created usingEncodingFactory.newJSONEncoding(Class, Class)
.
An JSON4J specific instance is obtained usingEncodingFactory.getJSONEncoding()
.- Since:
- InfoSphere® Streams Version 3.0
- See Also:
EncodingFactory.getJSONEncoding()
,EncodingFactory.getGenericJSONEncoding()
,EncodingFactory.newJSONEncoding(Class, Class)
, http://www.json.org/
-
-
Method Summary
Methods Modifier and Type Method and Description java.lang.String
encodeAsString(Tuple tuple)
Encode all attributes fortuple
into a string representation of a JSON object.O
encodeTuple(Tuple tuple)
Encode all attributes fortuple
into a JSON object.O
encodeTuple(Tuple tuple, O data)
Encode all attributes fortuple
as a JSON object.java.lang.Object
getAttributeObject(Tuple tuple, Attribute attribute)
Get an attribute value fromtuple
as object for a JSON object.java.lang.Object
getAttributeObject(Tuple tuple, java.lang.String attributeName)
Get an attribute value fromtuple
as an object for a JSON object.A
newJSONArray()
Return a new JSONObject.O
newJSONObject()
Return a new JSONObject.
-
-
-
Method Detail
-
getAttributeObject
java.lang.Object getAttributeObject(Tuple tuple, Attribute attribute)
Get an attribute value fromtuple
as object for a JSON object. The attribute's value is returned as a object that is an instance ofBoolean
,Number
,String
,O
(JSON object) orA
(JSON array).
Type mapping to JSON values Type.MetaType
JSON value type BOOLEAN
Boolean
INT8
Byte
INT16
Short
INT32
Integer
INT64
Long
FLOAT32
Float
FLOAT64
Double
DECIMAL32
,DECIMAL64
,DECIMAL128
java.math.BigDecimal
UINT8
,UINT16
Integer
(as the unsigned value)UINT32
Long
(as the unsigned value)UINT64
java.math.BigInteger
(as the unsigned value)RSTRING
,USTRING
,BSTRING
String
ENUM
String
TUPLE
O
(JSON object)TIMESTAMP
java.math.BigDecimal
(fromTimestamp.getTimeAsSeconds()
)MAP
,BMAP
O
(JSON object)LIST
,BLIST
SET
,BSET
A
(JSON array)- Parameters:
tuple
- Tuple to extract value from.attribute
- Attribute description. Ifattribute
does not represent an attribute intuple
the behavior is undefined.- Returns:
- An object that can be put into a JSON object or array
- Throws:
java.lang.UnsupportedOperationException
- Attribute cannot be represented in JSON.
-
getAttributeObject
java.lang.Object getAttributeObject(Tuple tuple, java.lang.String attributeName)
Get an attribute value fromtuple
as an object for a JSON object.- Parameters:
tuple
- Tuple to extract value from.attributeName
- Attribute name.- Returns:
- An object representing the attribute's value
- See Also:
getAttributeObject(Tuple, Attribute)
-
newJSONObject
O newJSONObject()
Return a new JSONObject. Uses the no-arg constructor ofO
to create a new instance.- Returns:
- A new instance of
O
-
newJSONArray
A newJSONArray()
Return a new JSONObject. Uses the no-arg constructor ofA
to create a new instance.- Returns:
- A new instance of
A
-
encodeTuple
O encodeTuple(Tuple tuple, O data)
Encode all attributes fortuple
as a JSON object. The keys for the JSON object are the attribute names and the values are objects fromgetAttributeObject(Tuple, Attribute)
.- Parameters:
tuple
- Tuple to be encoded.data
- JSON object to be populated.- Returns:
- data
- See Also:
getAttributeObject(Tuple, Attribute)
-
encodeTuple
O encodeTuple(Tuple tuple)
Encode all attributes fortuple
into a JSON object.- Parameters:
tuple
- Tuple to be encoded.- Returns:
- JSON object containing the attributes.
-
encodeAsString
java.lang.String encodeAsString(Tuple tuple) throws java.io.IOException
Encode all attributes fortuple
into a string representation of a JSON object.- Parameters:
tuple
- Tuple to be encoded- Returns:
- String representation of a JSON object
- Throws:
java.io.IOException
-
-