Class JacksonOpenApiMapperProvider
java.lang.Object
io.micronaut.openapi.jackson.JacksonOpenApiMapperProvider
- All Implemented Interfaces:
OpenApiMapperProvider
OpenApiMapperProvider backed by Jackson, using the mappers from OpenApiUtils.- Since:
- 8.0.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindNamingStrategy(String name) Resolves one of the well-known property naming strategies, such asSNAKE_CASEorKEBAB_CASE.findNamingStrategyClass(String className, ClassLoader classLoader) Resolves a naming strategy declared by class name, for example from a@JsonNamingannotation.io.micronaut.json.JsonMappergetMapper(OpenApiMapperType type, OpenApiVersion version) Returns the mapper for the given type and OpenAPI version.getName()<T> TupdateValue(io.micronaut.json.JsonMapper mapper, T valueToUpdate, io.micronaut.json.tree.JsonNode tree) Updates an existing value from a tree and returns the result.
-
Field Details
-
NAME
-
-
Constructor Details
-
JacksonOpenApiMapperProvider
public JacksonOpenApiMapperProvider()
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceOpenApiMapperProvider- Returns:
- The provider name, used to select it with "micronaut.openapi.mapper", for example
jacksonorserde.
-
getMapper
Description copied from interface:OpenApiMapperProviderReturns 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 areJsonNodeinstances.- Specified by:
getMapperin interfaceOpenApiMapperProvider- Parameters:
type- The mapper typeversion- 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:OpenApiMapperProviderUpdates 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 thanvalueToUpdate: with Jackson, a type whose deserializer cannot merge into an existing instance (such asSchema) is read into a new one, and the visitor must continue with that. The default implementation updates the value in place withupdateValueFromTreeand returns it, which is what a provider whose deserializers always merge should do.- Specified by:
updateValuein interfaceOpenApiMapperProvider- Type Parameters:
T- The value type- Parameters:
mapper- A mapper obtained fromOpenApiMapperProvider.getMapper(OpenApiMapperType, OpenApiVersion)valueToUpdate- The value to updatetree- The tree to read- Returns:
- The updated value
- Throws:
IOException- if the tree cannot be read
-
findNamingStrategy
Description copied from interface:OpenApiMapperProviderResolves one of the well-known property naming strategies, such asSNAKE_CASEorKEBAB_CASE.- Specified by:
findNamingStrategyin interfaceOpenApiMapperProvider- 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:OpenApiMapperProviderResolves a naming strategy declared by class name, for example from a@JsonNamingannotation.- Specified by:
findNamingStrategyClassin interfaceOpenApiMapperProvider- Parameters:
className- The fully qualified class name of the strategyclassLoader- 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
-