Class JsonUtils


  • public final class JsonUtils
    extends java.lang.Object
    Provides convenience methods for dealing with JSON nodes, arrays etc.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean bool​(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String name)
      Returns the specified node property as a boolean.
      static com.fasterxml.jackson.databind.node.ObjectNode envelope​(java.lang.String type, com.fasterxml.jackson.databind.node.ObjectNode payload)
      Composes a message structure for the given message type and payload.
      static java.lang.String eventType​(com.fasterxml.jackson.databind.node.ObjectNode event)
      Returns the event type from the specified event.
      static com.fasterxml.jackson.databind.node.ObjectNode node​(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String name)
      Returns the specified node property as an object node.
      static long number​(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String name)
      Returns the specified node property as a number.
      static com.fasterxml.jackson.databind.node.ObjectNode payload​(com.fasterxml.jackson.databind.node.ObjectNode event)
      Returns the payload from the specified event.
      static java.lang.String string​(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String name)
      Returns the specified node property as a string.
      static java.lang.String string​(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String name, java.lang.String defaultValue)
      Returns the specified node property as a string, with a default fallback.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • envelope

        public static com.fasterxml.jackson.databind.node.ObjectNode envelope​(java.lang.String type,
                                                                              com.fasterxml.jackson.databind.node.ObjectNode payload)
        Composes a message structure for the given message type and payload.
        Parameters:
        type - message type
        payload - message payload
        Returns:
        the object node representation
      • eventType

        public static java.lang.String eventType​(com.fasterxml.jackson.databind.node.ObjectNode event)
        Returns the event type from the specified event. If the node does not have an "event" property, "unknown" is returned.
        Parameters:
        event - message event
        Returns:
        extracted event type
      • payload

        public static com.fasterxml.jackson.databind.node.ObjectNode payload​(com.fasterxml.jackson.databind.node.ObjectNode event)
        Returns the payload from the specified event.
        Parameters:
        event - message event
        Returns:
        extracted payload object
      • number

        public static long number​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                  java.lang.String name)
        Returns the specified node property as a number.
        Parameters:
        node - object node
        name - property name
        Returns:
        property as number
      • string

        public static java.lang.String string​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                              java.lang.String name)
        Returns the specified node property as a string.
        Parameters:
        node - object node
        name - property name
        Returns:
        property as a string
      • string

        public static java.lang.String string​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                              java.lang.String name,
                                              java.lang.String defaultValue)
        Returns the specified node property as a string, with a default fallback.
        Parameters:
        node - object node
        name - property name
        defaultValue - fallback value if property is absent
        Returns:
        property as a string
      • node

        public static com.fasterxml.jackson.databind.node.ObjectNode node​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                                                          java.lang.String name)
        Returns the specified node property as an object node.
        Parameters:
        node - object node
        name - property name
        Returns:
        property as a node
      • bool

        public static boolean bool​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                   java.lang.String name)
        Returns the specified node property as a boolean.
        Parameters:
        node - object node
        name - property name
        Returns:
        property as a boolean