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:
eric.wittmann@gmail.com
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.fasterxml.jackson.databind.node.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.
    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>>
    void
    enumProperty(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
     
    static Object
    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.
    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 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 - JsonNode
      propertyName - 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 - ObjectNode
      propertyName - Property to be set
      propertyValue - 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 - ObjectNode
      propertyName - Property to be set
      propertyValue - 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 - JsonNode
      propertyName - 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 - ObjectNode
      propertyName - Property to be set
      propertyValue - 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 - JsonNode
      propertyName - 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 - ObjectNode
      propertyName - Property to be set
      propertyValue - 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 - JsonNode
      propertyName - 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 - ObjectNode
      propertyName - Property to be set
      propertyValue - 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
    • 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