Interface | Description |
---|---|
PayloadConverter<I,O> |
The base interface that a payload converter implements.
|
A payload converter provides conversion or transformation of values. It takes an input value, performs required manipulation and returns an output value, which can be of same or different format.
Payload converters may be specified for services within the
SourceHandler.SourceServiceProperties
for source services or
SinkHandler.SinkServiceProperties
for sink services.
The payload converter specified in the source service should convert the input value
into a Diffusion topic type.
In this case, values from an external system are passed to a
Publisher
within a
SourceHandler
or
HybridHandler
and
is converted into specific Diffusion topic type using the converter.
The payload converter specified in the sink service should convert the value
from the Diffusion topic type.
In this case, the converter converts values from a Diffusion data type
to an external data type before passing values to a
SinkHandler
via
its update
method, or to a HybridHandler
via its update
method.
Topic Type |
Converter name | Description |
---|---|---|
BINARY |
"$Object_to_BINARY" | If the value is an instance of
Binary , it is
returned as is.If the value is a byte[], it will be converted to a Binary object.
The caller must not write further data to the array.All other types will throw a PayloadConversionException . |
DOUBLE |
"$Object_to_Double" | If the value is an instance of Double , it is returned as is.If the value is an instance of Number , the product of its
doubleValue method is returned.If the value is null, null will be returned (leading to a null topic value}. For any other type the Double#parseDouble method is used on the
toString value of the supplied value and if the
string value cannot be parsed as a double, a
PayloadConversionException will be thrown. |
INT64 |
"$Object_to_Long" | If the value is an instance of Long , it is returned as is.If the value is an instance of Number , the product
of its longValue method is returned.If the value is null, null will be returned (leading to a null topic value}. For any other type the parseLong method is
used on the toString value of the supplied
value and if the string value cannot be parsed as a long, a
PayloadConversionException will be thrown. |
JSON |
"$Object_to_JSON" | If the value is an instance of
JSON , it is returned
as is.If a null value is passed, JSON containing "null" will be returned. Otherwise the input object will be converted to a JSON object.
Supported types of input objects are basic POJOs, primitives, and collections
such as Map and List.If the input value does not contain valid JSON, a PayloadConversionException is thrown. |
STRING |
"$Object_to_String" | If the value is null, null is returned (leading to a null topic
value). If the value is a String it is returned as is.For any other type the product of its toString method is returned. |
Topic Type |
Converter name | Description |
---|---|---|
BINARY |
"$BINARY_to_byte_array" | A byte[] representation of the topic's
Binary value is
returned. This is a byte[] view of the actual value and as such must not be
modified. |
JSON |
"$JSON_to_String" | A String is returned which contains the string
representation of the JSON object. |
Apart from these converters for Diffusion topic types, there are other converters issued with the framework. See the user guide for more details
A payload converter must implement PayloadConverter
interface.
The input or output type of the converter can be anything that could also be the Diffusion topic type to which the
service will be mapped.
The Diffusion com.pushtechnology.diffusion.datatype package
(described within the Diffusion Client API) should be used for reading and
writing Diffusion values.
ServiceHandler
, the converter instance is instantiated by the framework.
Converters that require construction parameters are instantiated by calling their
constructor with user-configured parameters.
Payload converters are called in line when publishing or updating and so must operate synchronously. However, there is no reason why a converter should not call out to some external service to perform a conversion as long as it blocks awaiting the response.
Copyright © 2024 DiffusionData Limited. All rights reserved.