Class JsonUtils


  • public final class JsonUtils
    extends 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, String name)
      Returns the specified node property as a boolean.
      static com.fasterxml.jackson.databind.node.ObjectNode envelope​(String type, com.fasterxml.jackson.databind.node.ObjectNode payload)
      Composes a message structure for the given message type and payload.
      static 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, String name)
      Returns the specified node property as an object node.
      static long number​(com.fasterxml.jackson.databind.node.ObjectNode node, 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 String string​(com.fasterxml.jackson.databind.node.ObjectNode node, String name)
      Returns the specified node property as a string.
      static String string​(com.fasterxml.jackson.databind.node.ObjectNode node, String name, String defaultValue)
      Returns the specified node property as a string, with a default fallback.
    • Method Detail

      • envelope

        public static com.fasterxml.jackson.databind.node.ObjectNode envelope​(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 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,
                                  String name)
        Returns the specified node property as a number.
        Parameters:
        node - object node
        name - property name
        Returns:
        property as number
      • string

        public static String string​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                    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 String string​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                    String name,
                                    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,
                                                                          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,
                                   String name)
        Returns the specified node property as a boolean.
        Parameters:
        node - object node
        name - property name
        Returns:
        property as a boolean