Package io.smallrye.openapi.runtime.io
Class JsonUtil
- java.lang.Object
-
- io.smallrye.openapi.runtime.io.JsonUtil
-
public final class JsonUtil extends Object
Utilities methods for reading information from a Json Tree.- Author:
- [email protected]
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.node.ArrayNode
arrayNode()
static BigDecimal
bigDecimalProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a BigDecimal property from the given json tree.static void
bigDecimalProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, BigDecimal propertyValue)
Sets the value of a property for a given json node.static Optional<Boolean>
booleanProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a boolean property from the given json tree.static void
booleanProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, Boolean propertyValue)
Sets the value of a property for a given json node.static <E extends Enum<E>>
voidenumProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, E propertyValue)
Sets the value of a property for a given json node.static Integer
intProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a integer property from the given json tree.static void
intProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, Integer propertyValue)
Sets the value of a property for a given json node.static com.fasterxml.jackson.databind.node.ObjectNode
objectNode()
static Object
parseValue(String value)
Parses an extension value.static Object
readObject(com.fasterxml.jackson.databind.JsonNode node)
Reads the node as a Java object.This is typically expected to be a literal of some sort, as in the case of default values and examples.static Optional<List<Object>>
readObjectArray(com.fasterxml.jackson.databind.JsonNode node)
Reads an object array.static Optional<List<String>>
readStringArray(com.fasterxml.jackson.databind.JsonNode node)
Reads a string array.static Optional<Map<String,String>>
readStringMap(com.fasterxml.jackson.databind.JsonNode node)
Reads a map of strings.static String
stringProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a string property from the given json tree.static void
stringProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, String propertyValue)
Sets the value of a property for a given json node.
-
-
-
Method Detail
-
objectNode
public static com.fasterxml.jackson.databind.node.ObjectNode objectNode()
-
arrayNode
public static com.fasterxml.jackson.databind.node.ArrayNode arrayNode()
-
stringProperty
public static String stringProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a string property from the given json tree. Returns null if no property exists or is not a text node.- Parameters:
node
- JsonNodepropertyName
- Property to extract- Returns:
- String holding the value found for the property
-
stringProperty
public static void stringProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, String propertyValue)
Sets the value of a property for a given json node. If the value is null, then the property is not written.- Parameters:
node
- ObjectNodepropertyName
- Property to be setpropertyValue
- Value to be set
-
enumProperty
public static <E extends Enum<E>> void enumProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, E propertyValue)
Sets the value of a property for a given json node. If the value is null, then the property is not written.- Type Parameters:
E
- Type of the property value- Parameters:
node
- ObjectNodepropertyName
- Property to be setpropertyValue
- Value to be set
-
booleanProperty
public static Optional<Boolean> booleanProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a boolean property from the given json tree. Returns null if no property exists or is not a boolean node.- Parameters:
node
- JsonNodepropertyName
- Property to extract- Returns:
- Boolean containing the value extracted
-
booleanProperty
public static void booleanProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, Boolean propertyValue)
Sets the value of a property for a given json node. If the value is null, then the property is not written.- Parameters:
node
- ObjectNodepropertyName
- Property to be setpropertyValue
- Boolean value to be set
-
intProperty
public static Integer intProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a integer property from the given json tree. Returns null if no property exists or is not a boolean node.- Parameters:
node
- JsonNodepropertyName
- Property to extract- Returns:
- Integer containing the extracted value
-
intProperty
public static void intProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, Integer propertyValue)
Sets the value of a property for a given json node. If the value is null, then the property is not written.- Parameters:
node
- ObjectNodepropertyName
- Property to be setpropertyValue
- Integer value to be set
-
bigDecimalProperty
public static BigDecimal bigDecimalProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName)
Extract a BigDecimal property from the given json tree. Returns null if no property exists or is not a boolean node.- Parameters:
node
- JsonNodepropertyName
- Property to extract- Returns:
- BigDecimal containing the extracted value
-
bigDecimalProperty
public static void bigDecimalProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, BigDecimal propertyValue)
Sets the value of a property for a given json node. If the value is null, then the property is not written.- Parameters:
node
- ObjectNodepropertyName
- Property to be setpropertyValue
- BigDecimal value to be set
-
readObject
public static Object readObject(com.fasterxml.jackson.databind.JsonNode node)
Reads the node as a Java object.This is typically expected to be a literal of some sort, as in the case of default values and examples. The node may be anything from a string to a javascript object.- Parameters:
node
- the json node- Returns:
- a java object
-
parseValue
public static Object parseValue(String value)
Parses an extension value. The value may be: - JSON object - starts with { - JSON array - starts with [ - number - boolean - string- Parameters:
value
- the value to parse- Returns:
- Extension
-
readStringArray
public static Optional<List<String>> readStringArray(com.fasterxml.jackson.databind.JsonNode node)
Reads a string array.- Parameters:
node
- the json node- Returns:
- List of strings
-
readObjectArray
public static Optional<List<Object>> readObjectArray(com.fasterxml.jackson.databind.JsonNode node)
Reads an object array.- Parameters:
node
- the json node- Returns:
- list of objects
-
-