public class JsonObjectSplitter extends MessageSplitterImp
If the message cannot be parsed as JSON then an exception will be thrown; If the message is an empty JSON object then the original message is returned. Note that because it operates on the entire payload, size of message considerations may be in order.
For instance the JSON Object
{"entry":[{"location":"Seattle","name":"Production System"},{"location":"New York","name":"R&D sandbox"}],"notes":"Some Notes","version":0.5}
would be split into 3 messages (the entry
, notes
and version
). JSON arrays will be split so that each
element of the array becomes a separate message, so
[{colour: "red",value: "#f00"},{colour: "green",value: "#0f0"},{colour: "blue",value: "#00f"},{colour: "black",value: "#000"}]
would be split into 4 messages.
In the adapter configuration file this class is aliased as json-object-splitter which is the preferred alternative to the fully qualified classname when building your configuration.
MessageSplitterImp.SplitMessageIterator
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
LOGGER
Default logger.
|
logR
Constructor and Description |
---|
JsonObjectSplitter() |
Modifier and Type | Method and Description |
---|---|
protected AdaptrisMessage |
createSplitMessage(net.minidev.json.JSONObject json,
AdaptrisMessage message)
Create a new Adaptris message for the given JSON object.
|
java.util.List<AdaptrisMessage> |
splitMessage(AdaptrisMessage message)
Split a JSON payload from an Adaptris message.
|
protected java.util.List<AdaptrisMessage> |
splitMessage(net.minidev.json.JSONArray array,
AdaptrisMessage message)
Split a JSON array into a list of Adaptris messages for each JSON array element.
|
copyMetadata, getCopyMetadata, getCopyObjectMetadata, getMessageFactory, selectFactory, setCopyMetadata, setCopyObjectMetadata, setMessageFactory
public java.util.List<AdaptrisMessage> splitMessage(AdaptrisMessage message) throws CoreException
message
- The Adaptris message.CoreException
protected java.util.List<AdaptrisMessage> splitMessage(net.minidev.json.JSONArray array, AdaptrisMessage message) throws java.io.IOException
array
- The JSON array.message
- The original Adaptris message.java.io.IOException
- If IOUtils cannot copy from a Reader to a Writer (see createSplitMessage(JSONObject, AdaptrisMessage)
.protected AdaptrisMessage createSplitMessage(net.minidev.json.JSONObject json, AdaptrisMessage message) throws java.io.IOException
json
- The JSON object.message
- The original Adaptris message.java.io.IOException
- If IOUtils cannot copy from a Reader to a Writer.