public class JSONReader extends Object implements SmooksXMLReader
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.json.JSONReader</resource>
<!--
(Optional) The element name of the SAX document root. Default of 'json'.
-->
<param name="rootName"><root-name></param>
<!--
(Optional) The element name of a array element. Default of 'element'.
-->
<param name="arrayElementName"><array-element-name></param>
<!--
(Optional) The replacement string for JSON NULL values. Default is an empty string.
-->
<param name="nullValueReplacement"><null-value-replacement></param>
<!--
(Optional) The replacement character for whitespaces in a json map key. By default this not defined, so that the reader doesn't search for whitespaces.
-->
<param name="keyWhitspaceReplacement"><key-whitspace-replacement></param>
<!--
(Optional) The prefix character to add if the JSON node name starts with a number. By default this is not defined, so that the reader doesn't search for element names that start with a number.
-->
<param name="keyPrefixOnNumeric"><key-prefix-on-numeric></param>
<!--
(Optional) If illegal characters are encountered in a JSON element name then they are replaced with this value. By default this is not defined, so that the reader doesn't doesn't search for illegal characters.
-->
<param name="illegalElementNameCharReplacement"><illegal-element-name-char-replacement></param>
<!--
(Optional) Defines a map of keys and there replacement. The from key will be replaced with the to key or the contents of the element.
-->
<param name="keyMap">
<key from="fromKey" to="toKey" />
<key from="fromKey"><to></key>
</param>
<!--
(Optional) The encoding of the input stream. Default of 'UTF-8'
-->
<param name="encoding"><encoding></param>
</resource-config>
<resource-config selector="org.xml.sax.driver"> <resource>org.milyn.json.JSONReader</resource> </smooks-resource>The "Acme-Order-List" input JSON message:
[
{
"name" : "Maurice Zeijen",
"address" : "Netherlands",
"item" : "V1234",
"quantity" : 3
},
{
"name" : "Joe Bloggs",
"address" : "England",
"item" : "D9123",
"quantity" : 7
},
]
Within Smooks, the stream of SAX events generated by the "Acme-Order-List" message (and this reader) will generate
a DOM equivalent to the following:
<json> <element> <name>Maurice Zeijen</name> <address>Netherlands</address> <item>V1234</item> <quantity>3</quantity> <element> <element> <name>Joe Bloggs</name> <address>England</address> <item>D9123</item> <quantity>7</quantity> <element> </json>
| Modifier and Type | Field and Description |
|---|---|
static String |
CONFIG_PARAM_KEY_MAP |
static String |
DEFAULT_NULL_VALUE_REPLACEMENT |
static String |
XML_ARRAY_ELEMENT_NAME |
static String |
XML_ROOT |
| Constructor and Description |
|---|
JSONReader() |
public static final String CONFIG_PARAM_KEY_MAP
public static final String XML_ROOT
public static final String XML_ARRAY_ELEMENT_NAME
public static final String DEFAULT_NULL_VALUE_REPLACEMENT
@Initialize public void initialize()
public void setExecutionContext(ExecutionContext request)
SmooksXMLReaderExecutionContext on the implementing class.setExecutionContext in interface SmooksXMLReaderrequest - The Smooks ExecutionContext.public void parse(InputSource csvInputSource) throws IOException, SAXException
parse in interface XMLReaderIOExceptionSAXExceptionpublic void setContentHandler(ContentHandler contentHandler)
setContentHandler in interface XMLReaderpublic ContentHandler getContentHandler()
getContentHandler in interface XMLReaderpublic void setKeyMap(HashMap<String,String> keyMap)
keyMap - the keyMap to setpublic String getRootName()
public void setRootName(String rootName)
rootName - the rootName to setpublic String getArrayElementName()
public void setArrayElementName(String arrayElementName)
arrayElementName - the arrayElementName to setpublic String getKeyWhitspaceReplacement()
public void setKeyWhitspaceReplacement(String keyWhitspaceReplacement)
keyWhitspaceReplacement - the keyWhitspaceReplacement to setpublic String getKeyPrefixOnNumeric()
public void setKeyPrefixOnNumeric(String keyPrefixOnNumeric)
keyPrefixOnNumeric - the keyPrefixOnNumeric to setpublic String getIllegalElementNameCharReplacement()
public void setIllegalElementNameCharReplacement(String illegalElementNameCharReplacement)
illegalElementNameCharReplacement - the illegalElementNameCharReplacement to setpublic String getNullValueReplacement()
public void setNullValueReplacement(String nullValueReplacement)
nullValueReplacement - the nullValueReplacement to setpublic Charset getEncoding()
public void setEncoding(Charset encoding)
encoding - the encoding to setpublic void setIndent(boolean indent)
public void parse(String systemId)
public boolean getFeature(String name)
getFeature in interface XMLReaderpublic void setFeature(String name, boolean value)
setFeature in interface XMLReaderpublic DTDHandler getDTDHandler()
getDTDHandler in interface XMLReaderpublic void setDTDHandler(DTDHandler arg0)
setDTDHandler in interface XMLReaderpublic EntityResolver getEntityResolver()
getEntityResolver in interface XMLReaderpublic void setEntityResolver(EntityResolver arg0)
setEntityResolver in interface XMLReaderpublic ErrorHandler getErrorHandler()
getErrorHandler in interface XMLReaderpublic void setErrorHandler(ErrorHandler arg0)
setErrorHandler in interface XMLReaderpublic Object getProperty(String name)
getProperty in interface XMLReaderpublic void setProperty(String name, Object value)
setProperty in interface XMLReaderCopyright © 2020. All rights reserved.