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 |
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 |
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 |
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.
|
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 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.