@ComponentProfile(summary="Simple JSON/XML Transformation driver", tag="json,xml,transformation") public class SimpleJsonTransformationDriver extends java.lang.Object implements TransformationDriver
This uses the default json.org implementation to convert between JSON and XML.
When converting to XML, it will add a root element called json
(this is configurable via
setJsonTag(String)
) as the required XML root element. When converting from XML then it expects the same
tag as the root element of the XML.
If your input is a relatively JSON object, then this is the transformation driver to use; DefaultJsonTransformationDriver
adds a layer of XML complexity that you may not need. The key differentiator is that where the output should be
a JSON array with a single element; it will not be supported by this driver implementation. You can still use it, but you will
have to execute a JsonTransformService
afterwards to change the cardinality.
If the input is a JSON array, then json-array
(not configurable) will be added as the root element, that wraps the JSON
array.
In the adapter configuration file this class is aliased as simple-transformation-driver which is the preferred alternative to the fully qualified classname when building your configuration.
Constructor and Description |
---|
SimpleJsonTransformationDriver() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getJsonTag()
Get the JSON tag.
|
void |
setJsonTag(java.lang.String jsonTag)
Set the JSON tag.
|
java.lang.String |
transform(java.lang.String input,
TransformationDirection direction)
Perform transformation.
|
public java.lang.String transform(java.lang.String input, TransformationDirection direction) throws ServiceException
transform
in interface TransformationDriver
input
- The data to transform.direction
- The direction of the transformation.ServiceException
- Thrown if there is a problem with the transformation.public java.lang.String getJsonTag()
public void setJsonTag(java.lang.String jsonTag)
jsonTag
- The JSON tag.