Class JacksonOpenApiMapperProvider

java.lang.Object
io.micronaut.openapi.jackson.JacksonOpenApiMapperProvider
All Implemented Interfaces:
OpenApiMapperProvider

public final class JacksonOpenApiMapperProvider extends Object implements OpenApiMapperProvider
OpenApiMapperProvider backed by Jackson, using the mappers from OpenApiUtils.
Since:
8.0.0
  • Field Details

  • Constructor Details

    • JacksonOpenApiMapperProvider

      public JacksonOpenApiMapperProvider()
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface OpenApiMapperProvider
      Returns:
      The provider name, used to select it with "micronaut.openapi.mapper", for example jackson or serde.
    • getMapper

      public io.micronaut.json.JsonMapper getMapper(OpenApiMapperType type, OpenApiVersion version)
      Description copied from interface: OpenApiMapperProvider
      Returns the mapper for the given type and OpenAPI version.

      The returned mapper must serialize the OpenAPI model classes (swagger-models) according to the OpenAPI specification: extensions written as top-level x- properties, enums written by their specification value and so on. Trees exchanged with the visitor are JsonNode instances.

      Specified by:
      getMapper in interface OpenApiMapperProvider
      Parameters:
      type - The mapper type
      version - The OpenAPI version of the document
      Returns:
      The mapper
    • updateValue

      public <T> T updateValue(io.micronaut.json.JsonMapper mapper, T valueToUpdate, io.micronaut.json.tree.JsonNode tree) throws IOException
      Description copied from interface: OpenApiMapperProvider
      Updates an existing value from a tree and returns the result.

      The visitor uses this instead of JsonMapper.updateValueFromTree(Object, JsonNode) because the result may be a different instance than valueToUpdate: with Jackson, a type whose deserializer cannot merge into an existing instance (such as Schema) is read into a new one, and the visitor must continue with that. The default implementation updates the value in place with updateValueFromTree and returns it, which is what a provider whose deserializers always merge should do.

      Specified by:
      updateValue in interface OpenApiMapperProvider
      Type Parameters:
      T - The value type
      Parameters:
      mapper - A mapper obtained from OpenApiMapperProvider.getMapper(OpenApiMapperType, OpenApiVersion)
      valueToUpdate - The value to update
      tree - The tree to read
      Returns:
      The updated value
      Throws:
      IOException - if the tree cannot be read
    • findNamingStrategy

      public Optional<UnaryOperator<String>> findNamingStrategy(String name)
      Description copied from interface: OpenApiMapperProvider
      Resolves one of the well-known property naming strategies, such as SNAKE_CASE or KEBAB_CASE.
      Specified by:
      findNamingStrategy in interface OpenApiMapperProvider
      Parameters:
      name - The upper case strategy name
      Returns:
      The function translating a property name, or empty if the strategy is unknown
    • findNamingStrategyClass

      public Optional<UnaryOperator<String>> findNamingStrategyClass(String className, ClassLoader classLoader)
      Description copied from interface: OpenApiMapperProvider
      Resolves a naming strategy declared by class name, for example from a @JsonNaming annotation.
      Specified by:
      findNamingStrategyClass in interface OpenApiMapperProvider
      Parameters:
      className - The fully qualified class name of the strategy
      classLoader - The class loader to load it with
      Returns:
      The function translating a property name, or empty if the provider cannot apply that strategy, in which case the visitor warns and keeps the property names unchanged