Class ConvertUtils

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

@Internal public final class ConvertUtils extends Object
Convert utilities methods.
Since:
4.4.1
  • Field Details

    • MAP_TYPE_REFERENCE

      public static final com.fasterxml.jackson.core.type.TypeReference<Map<String,Object>> MAP_TYPE_REFERENCE
  • Method Details

    • toValue

      public static <T> T toValue(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context, Class<T> type)
      Convert the given Map to a JSON node and then to the specified type.
      Type Parameters:
      T - The output class type
      Parameters:
      values - The values
      context - The visitor context
      type - The class
      Returns:
      The converted instance
    • toJson

      public static com.fasterxml.jackson.databind.JsonNode toJson(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context)
      Convert the given map to a JSON node.
      Parameters:
      values - The values
      context - The visitor context
      Returns:
      The node
    • toValueMap

      public static Map<CharSequence,Object> toValueMap(Map<CharSequence,Object> values, io.micronaut.inject.visitor.VisitorContext context)
    • parseJsonString

      public static Optional<Object> parseJsonString(Object object)
    • treeToValue

      public static <T> T treeToValue(com.fasterxml.jackson.databind.JsonNode jn, Class<T> clazz, io.micronaut.inject.visitor.VisitorContext context) throws com.fasterxml.jackson.core.JsonProcessingException
      Converts Json node into a class' instance or throws 'com.fasterxml.jackson.core.JsonProcessingException', adds extensions if present.
      Type Parameters:
      T - The output class type
      Parameters:
      jn - The json node
      clazz - The output class instance
      context - visitor context
      Returns:
      The converted instance
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if error
    • normalizeValue

      public static Object normalizeValue(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context) throws com.fasterxml.jackson.core.JsonProcessingException
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • normalizeValue

      public static Object normalizeValue(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context, boolean isMicronautFormat) throws com.fasterxml.jackson.core.JsonProcessingException
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • resolveExtensions

      public static Optional<Map<String,Object>> resolveExtensions(com.fasterxml.jackson.databind.JsonNode jn)
    • mapToSecurityRequirement

      public static io.swagger.v3.oas.models.security.SecurityRequirement mapToSecurityRequirement(io.micronaut.core.annotation.AnnotationValue<io.swagger.v3.oas.annotations.security.SecurityRequirement> r)
      Maps annotation value to SecurityRequirement. Correct format is: custom_name: - custom_scope1 - custom_scope2
      Parameters:
      r - The value of SecurityRequirement.
      Returns:
      converted object.
    • setDefaultValueObject

      public static void setDefaultValueObject(io.swagger.v3.oas.models.media.Schema<?> schema, String defaultValue, @Nullable @Nullable io.micronaut.inject.ast.Element element, @Nullable @Nullable String schemaType, @Nullable @Nullable String schemaFormat, boolean isMicronautFormat, io.micronaut.inject.visitor.VisitorContext context)
    • checkEnumJsonValueType

      @NonNull public static @NonNull Pair<String,String> checkEnumJsonValueType(io.micronaut.inject.visitor.VisitorContext context, @NonNull @NonNull io.micronaut.inject.ast.EnumElement type, @Nullable @Nullable String schemaType, @Nullable @Nullable String schemaFormat)
      Detect openapi type and format for enums.
      Parameters:
      context - visitor context
      type - enum element
      schemaType - type from swagger Schema annotation
      schemaFormat - format from swagger Schema annotation
      Returns:
      pair with openapi type and format
    • getTypeAndFormatByClass

      public static Pair<String,String> getTypeAndFormatByClass(String className, boolean isArray)
      Detect openapi type and format by java class name.
      Parameters:
      className - java class name
      isArray - is it array
      Returns:
      pair with openapi type and format
    • parseByTypeAndFormat

      public static Object parseByTypeAndFormat(String valueStr, String type, String format, io.micronaut.inject.visitor.VisitorContext context, boolean isMicronautFormat)
      Parse value by openapi type and format.
      Parameters:
      valueStr - string value for parse
      type - openapi type
      format - openapi value
      context - visitor context
      isMicronautFormat - is it micronaut format for arrays
      Returns:
      parsed value