public class IDataJSONCoder extends IDataCoder
encode(OutputStream, IData)
and decode(InputStream)
methods are called directly from client applications or from these public services:
Modifier and Type | Class and Description |
---|---|
static class |
IDataJSONCoder.JSON_ENCODING
The character encodings that can be used by
encode(OutputStream, IData)
when generating JSON. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
WATT_SERVER_JSON_DECODE_INTEGER_AS_LONG |
static java.lang.String |
WATT_SERVER_JSON_DECODE_REAL_AS_DOUBLE |
static java.lang.String |
WATT_SERVER_JSON_PRETTY_PRINT |
Constructor and Description |
---|
IDataJSONCoder() |
Modifier and Type | Method and Description |
---|---|
IData |
decode(java.io.InputStream is)
Converts a stream of JSON content into an Integration Server document.
|
void |
encode(java.io.OutputStream os,
IData data)
Converts an Integration Server document to JSON and writes it to the supplied OutputStream.
|
java.lang.String |
getContentType()
Returns a String containing the name of the content type that is in use by this instance
of IDataCoder.
|
void |
setDateEncoding(java.lang.String encodeAs)
Indicates whether
Date instances in the IData
being encoded should become long timestamps or String s
in the JSON text returned by encode(OutputStream, IData) . |
void |
setDecodeIntegerAsLong(boolean value)
Indicates to the IDataJSONCoder whether to convert integer numbers in the JSON content
to java.lang.Longs or java.lang.Integers.
|
void |
setDecodeNullRootAsEmpty(boolean value)
Indicates to the IDataJSONCoder whether null scalar value at root in the JSON being parsed
should be converted to empty IData or to {"$rootValue":null}
|
void |
setDecodeRealAsDouble(boolean value)
Indicates to the IDataJSONCoder whether to convert real numbers in the JSON content
to java.lang.Floats or java.lang.Doubles.
|
void |
setDecodeRealAsString(boolean value)
Indicates to the IDataJSONCoder whether decimal numbers in the JSON being parsed
should be converted to java.lang.Strings.
|
void |
setEncoding(IDataJSONCoder.JSON_ENCODING encoding)
Indicates to the IDataJSONCoder which character encoding to use.
|
void |
setPrettyPrint(boolean prettyPrint)
Indicates to the IDataJSONCoder whether to use pretty print to format the JSON output.
|
void |
setUnescapeSpecialChars(boolean value)
Indicates to the IDataJSONCoder whether the escape characters will be un-escaped while
decoding the JSON string value.
|
decodeFromBytes, encodeToBytes, readFromFile, writeToFile
public static final java.lang.String WATT_SERVER_JSON_DECODE_INTEGER_AS_LONG
public static final java.lang.String WATT_SERVER_JSON_DECODE_REAL_AS_DOUBLE
public static final java.lang.String WATT_SERVER_JSON_PRETTY_PRINT
public java.lang.String getContentType()
IDataCoder
getContentType
in class IDataCoder
public void encode(java.io.OutputStream os, IData data) throws java.io.IOException, InvalidDatatypeException
encode(OutputStream, IData)
is controlled by the
watt.server.json.prettyPrint property. The default setting for this property
is false, which causes encode to generate compact JSON, with no
additional carriage returns or indentation. If watt.server.json.prettyPrint is
true, the generated JSON is formatted with carriage returns and indentation to
make the output easier to read. You can override the setting of this property by calling the
setPrettyPrint(boolean)
method prior to the encode method.Field names in the generated JSON text are enclosed in double quotes by default. This conforms to the JSON standard. If the JSON text will be consumed by an older JavaScript processor that does not handle quoted field names correctly, you can set the watt.server.json.quoteFieldNames property to false to change this.
encode
in class IDataCoder
os
- the OutputStream to write the JSON content todata
- an Integration Server document to be transformed into JSONjava.io.IOException
InvalidDatatypeException
- If the data in the IData object cannot be encoded (i.e.,
the IData object contains an object type that is not supported by the specific
implementation of encode that you are using).#encode(OutputStream,Values)
public IData decode(java.io.InputStream is) throws java.io.IOException, InvalidDatatypeException
decode
in class IDataCoder
is
- an InputStream holding JSON contentValues
java.io.IOException
- If an error occurs while reading the InputStream or writing to the
IData object.InvalidDatatypeException
- If the content of InputStream cannot an be properly
parsed and decoded.#decodeToIData(InputStream)
public void setDecodeRealAsDouble(boolean value)
value
- If true, real numbers will be converted to Doubles.
If false, real numbers will be converted to Floats.public void setDecodeIntegerAsLong(boolean value)
value
- If true, real numbers will be converted to Longs.
If false, real numbers will be converted to Integers.public void setDecodeRealAsString(boolean value)
value
- If true, real numbers will be converted to Strings
If false, real numbers will not be converted to Stringspublic void setDecodeNullRootAsEmpty(boolean value)
value
- If true, null scalar value will be converted to empty IData
If false, null scalar value will be converted to {"$rootValue":null}public void setUnescapeSpecialChars(boolean value)
If
- true, the escape characters will be un-escaped in decoded string.
If false, the escape characters will be escaped in decoded string.public void setDateEncoding(java.lang.String encodeAs)
Date
instances in the IData
being encoded should become long
timestamps or String
s
in the JSON text returned by encode(OutputStream, IData)
. If setDateEncoding
is not called prior to encode(OutputStream, IData)
, the formatting specified in the
watt.server.json.encodeDateAs configuration parameter is used. If watt.server.json.encodeDateAs is
empty, or if encodeAs
is null or an empty string, the default formatting
provided by Date.toString()
is used.encodeAs
- Acceptable values are "long"
- A Java timestamp; seconds since January 1, 1970 00:00:00"ISO8601"
- The standard ISO8601 date format YYYY-MM-dd'T'HH:mm:ss.sss'Z'SimpleDateFormat
.null
- The default formatting provided by Date.toString()
,
EEE MMM dd hh:mm:ss zzz yyyySimpleDateFormat
public void setPrettyPrint(boolean prettyPrint)
#encode(OutputStream, Values)
or
encode(OutputStream, IData)
in order to override the current setting of the
watt.server.json.prettyPrint property.prettyPrint
- If true, calls to the encode methods will
generate JSON formatted with carriage returns and indentation to make the JSON output
easier to read. If false, the generated JSON will not include carriage returns
or indentation.public void setEncoding(IDataJSONCoder.JSON_ENCODING encoding)
encoding
- Specifies the encoding to use.