Package org.onosproject.ui
Class JsonUtils
- java.lang.Object
-
- org.onosproject.ui.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 typepayload
- 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 nodename
- 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 nodename
- 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 nodename
- property namedefaultValue
- 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 nodename
- 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 nodename
- property name- Returns:
- property as a boolean
-
-