Package io.smallrye.openapi.runtime.io
Class JsonUtil
java.lang.Object
io.smallrye.openapi.runtime.io.JsonUtil
Utilities methods for reading information from a Json Tree.
- Author:
- eric.wittmann@gmail.com
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.node.ArrayNodestatic BigDecimalbigDecimalProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName) Extract a BigDecimal property from the given json tree.static voidbigDecimalProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, BigDecimal propertyValue) Sets the value of a property for a given json node.booleanProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName) Extract a boolean property from the given json tree.static voidbooleanProperty(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 IntegerintProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName) Extract a integer property from the given json tree.static voidintProperty(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.ObjectNodestatic ObjectparseValue(String value) Parses an extension value.static ObjectreadObject(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.readObjectArray(com.fasterxml.jackson.databind.JsonNode node) Reads an object array.readStringArray(com.fasterxml.jackson.databind.JsonNode node) Reads a string array.readStringMap(com.fasterxml.jackson.databind.JsonNode node) Reads a map of strings.static StringstringProperty(com.fasterxml.jackson.databind.JsonNode node, String propertyName) Extract a string property from the given json tree.static voidstringProperty(com.fasterxml.jackson.databind.node.ObjectNode node, String propertyName, String propertyValue) Sets the value of a property for a given json node.
-
Method Details
-
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
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
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
Reads a string array.- Parameters:
node- the json node- Returns:
- List of strings
-
readObjectArray
Reads an object array.- Parameters:
node- the json node- Returns:
- list of objects
-
readStringMap
public static Optional<Map<String,String>> readStringMap(com.fasterxml.jackson.databind.JsonNode node) Reads a map of strings.- Parameters:
node- json map- Returns:
- a String-String map
-