Class JsonObjectSplitter
- java.lang.Object
-
- com.adaptris.core.services.splitter.MessageSplitterImp
-
- com.adaptris.core.services.splitter.json.JsonObjectSplitter
-
- All Implemented Interfaces:
MessageSplitter
- Direct Known Subclasses:
JsonArraySplitter
@ComponentProfile(summary="Split a JSON Object into individual JSON objects", tag="json,splitting") public class JsonObjectSplitter extends MessageSplitterImp
Message splitter implementation that splits a JSON object so each entry forms a new message.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 (theentry
,notes
andversion
). 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.adaptris.core.services.splitter.MessageSplitterImp
MessageSplitterImp.SplitMessageIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
LOGGER
Default logger.-
Fields inherited from class com.adaptris.core.services.splitter.MessageSplitterImp
logR
-
-
Constructor Summary
Constructors Constructor Description JsonObjectSplitter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class com.adaptris.core.services.splitter.MessageSplitterImp
copyMetadata, getCopyMetadata, getCopyObjectMetadata, getMessageFactory, selectFactory, setCopyMetadata, setCopyObjectMetadata, setMessageFactory
-
-
-
-
Method Detail
-
splitMessage
public java.util.List<AdaptrisMessage> splitMessage(AdaptrisMessage message) throws CoreException
Split a JSON payload from an Adaptris message. .- Parameters:
message
- The Adaptris message.- Returns:
- A list of Adaptris messages for each JSON object.
- Throws:
CoreException
-
splitMessage
protected java.util.List<AdaptrisMessage> splitMessage(net.minidev.json.JSONArray array, AdaptrisMessage message) throws java.io.IOException
Split a JSON array into a list of Adaptris messages for each JSON array element.- Parameters:
array
- The JSON array.message
- The original Adaptris message.- Returns:
- A list of Adaptris messages.
- Throws:
java.io.IOException
- If IOUtils cannot copy from a Reader to a Writer (seecreateSplitMessage(JSONObject, AdaptrisMessage)
.
-
createSplitMessage
protected AdaptrisMessage createSplitMessage(net.minidev.json.JSONObject json, AdaptrisMessage message) throws java.io.IOException
Create a new Adaptris message for the given JSON object.- Parameters:
json
- The JSON object.message
- The original Adaptris message.- Returns:
- A new Adaptris message for the JSON object.
- Throws:
java.io.IOException
- If IOUtils cannot copy from a Reader to a Writer.
-
-