Class 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 (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.

    • Field Detail

      • LOGGER

        protected static final org.slf4j.Logger LOGGER
        Default logger.
    • Constructor Detail

      • JsonObjectSplitter

        public JsonObjectSplitter()
    • 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 (see createSplitMessage(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.