Class MapperUtils

java.lang.Object
io.micronaut.openapi.visitor.MapperUtils

@Internal public final class MapperUtils extends Object
Helpers for using the JsonMapper of the selected OpenApiMapperProvider. Mapping failures are rethrown as UncheckedIOException.
Since:
8.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    convertValue(io.micronaut.json.JsonMapper mapper, @Nullable Object value, io.micronaut.core.type.Argument<T> type)
     
    static <T> T
    convertValue(io.micronaut.json.JsonMapper mapper, @Nullable Object value, Class<T> type)
     
    static boolean
    has(io.micronaut.json.tree.JsonNode node, String name)
     
    static io.micronaut.json.tree.JsonNode
    readTree(io.micronaut.json.JsonMapper mapper, String content)
     
    static <T> T
    readValue(io.micronaut.json.JsonMapper mapper, String content, io.micronaut.core.type.Argument<T> type)
     
    static <T> T
    readValue(io.micronaut.json.JsonMapper mapper, String content, Class<T> type)
     
    static <T> T
    readValue(io.micronaut.json.JsonMapper mapper, Path path, Class<T> type)
     
    static @Nullable String
    stringValue(@Nullable io.micronaut.json.tree.JsonNode node)
     
    static <T> T
    treeToValue(io.micronaut.json.JsonMapper mapper, io.micronaut.json.tree.JsonNode tree, io.micronaut.core.type.Argument<T> type)
     
    static <T> T
    treeToValue(io.micronaut.json.JsonMapper mapper, io.micronaut.json.tree.JsonNode tree, Class<T> type)
     
    static <T> T
    updateValue(io.micronaut.json.JsonMapper mapper, T valueToUpdate, io.micronaut.json.tree.JsonNode tree)
    static io.micronaut.json.tree.JsonNode
    valueToTree(io.micronaut.json.JsonMapper mapper, @Nullable Object value)
     
    static io.micronaut.json.tree.JsonNode
    with(io.micronaut.json.tree.JsonNode node, String name, io.micronaut.json.tree.JsonNode value)
     
    static io.micronaut.json.tree.JsonNode
    without(io.micronaut.json.tree.JsonNode node, String... names)
     
    static void
    writeValue(io.micronaut.json.JsonMapper mapper, Writer writer, @Nullable Object value)
     
    static String
    writeValueAsString(io.micronaut.json.JsonMapper mapper, @Nullable Object value)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • readValue

      @Nullable public static <T> T readValue(io.micronaut.json.JsonMapper mapper, String content, Class<T> type)
    • readValue

      @Nullable public static <T> T readValue(io.micronaut.json.JsonMapper mapper, String content, io.micronaut.core.type.Argument<T> type)
    • readValue

      @Nullable public static <T> T readValue(io.micronaut.json.JsonMapper mapper, Path path, Class<T> type)
    • readTree

      public static io.micronaut.json.tree.JsonNode readTree(io.micronaut.json.JsonMapper mapper, String content)
    • valueToTree

      public static io.micronaut.json.tree.JsonNode valueToTree(io.micronaut.json.JsonMapper mapper, @Nullable @Nullable Object value)
    • treeToValue

      @Nullable public static <T> T treeToValue(io.micronaut.json.JsonMapper mapper, io.micronaut.json.tree.JsonNode tree, Class<T> type)
    • treeToValue

      @Nullable public static <T> T treeToValue(io.micronaut.json.JsonMapper mapper, io.micronaut.json.tree.JsonNode tree, io.micronaut.core.type.Argument<T> type)
    • convertValue

      @Nullable public static <T> T convertValue(io.micronaut.json.JsonMapper mapper, @Nullable @Nullable Object value, Class<T> type)
    • convertValue

      @Nullable public static <T> T convertValue(io.micronaut.json.JsonMapper mapper, @Nullable @Nullable Object value, io.micronaut.core.type.Argument<T> type)
    • writeValueAsString

      public static String writeValueAsString(io.micronaut.json.JsonMapper mapper, @Nullable @Nullable Object value)
    • writeValue

      public static void writeValue(io.micronaut.json.JsonMapper mapper, Writer writer, @Nullable @Nullable Object value)
    • updateValue

      public static <T> T updateValue(io.micronaut.json.JsonMapper mapper, T valueToUpdate, io.micronaut.json.tree.JsonNode tree)
      Type Parameters:
      T - The value type
      Parameters:
      mapper - The mapper
      valueToUpdate - The value to update
      tree - The tree
      Returns:
      The updated value, possibly a new instance
    • stringValue

      @Nullable public static @Nullable String stringValue(@Nullable @Nullable io.micronaut.json.tree.JsonNode node)
      Parameters:
      node - A node, possibly null
      Returns:
      The string value of a string node, the text of any other scalar node, otherwise null
    • has

      public static boolean has(io.micronaut.json.tree.JsonNode node, String name)
      Parameters:
      node - An object node
      name - The property name
      Returns:
      Whether the object has the property
    • without

      public static io.micronaut.json.tree.JsonNode without(io.micronaut.json.tree.JsonNode node, String... names)
      Parameters:
      node - An object node
      names - The properties to remove
      Returns:
      A copy of the object without the given properties
    • with

      public static io.micronaut.json.tree.JsonNode with(io.micronaut.json.tree.JsonNode node, String name, io.micronaut.json.tree.JsonNode value)
      Parameters:
      node - An object node
      name - The property name
      value - The new value
      Returns:
      A copy of the object with the property set to the value