Interface ObjectMapper

All Superinterfaces:
io.micronaut.json.JsonMapper
All Known Subinterfaces:
ObjectMapper.CloseableObjectMapper
All Known Implementing Classes:
AbstractBsonMapper, BsonBinaryMapper, BsonJsonMapper, JacksonJsonMapper, JsonStreamMapper, OracleJdbcJsonBinaryObjectMapper, OracleJdbcJsonTextObjectMapper

public interface ObjectMapper extends io.micronaut.json.JsonMapper
Sub-interface of JsonMapper with customizations.
Author:
graemerocher
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A closeable object mapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    default io.micronaut.json.JsonMapper
    cloneWithFeatures(io.micronaut.json.JsonFeatures features)
     
    create(Map<String,Object> configuration, String... packageNames)
    Creates a new custom ObjectMapper with additional beans (serializers, deserializers etc.) loaded from the given package locations.
    Get the default ObjectMapper instance.
    default <T> T
    readValue(byte[] byteArray, Class<T> type)
    Read a value from the byte array for the given type.
    default <T> T
    readValue(InputStream inputStream, Class<T> type)
    Read a value from the given input stream for the given type.
    default <T> T
    readValue(String string, Class<T> type)
    Read a value from the given string for the given type.
    default <T> String
    writeValueAsString(io.micronaut.core.type.Argument<T> type, T object)
    Write the given value as a string.
    default <T> String
    writeValueAsString(io.micronaut.core.type.Argument<T> type, T object, Charset charset)
    Write the given value as a string.
    default <T> String
    Write the given value as a string.

    Methods inherited from interface io.micronaut.json.JsonMapper

    cloneWithViewClass, createReactiveParser, createSpecific, detectFeatures, getStreamConfig, readValue, readValue, readValue, readValue, readValueFromTree, readValueFromTree, updateValueFromTree, writeValue, writeValue, writeValueAsBytes, writeValueAsBytes, writeValueToTree, writeValueToTree
  • Method Details

    • readValue

      @Nullable default <T> T readValue(@NonNull InputStream inputStream, @NonNull Class<T> type) throws IOException
      Read a value from the given input stream for the given type.
      Type Parameters:
      T - The generic type
      Parameters:
      inputStream - The input stream
      type - The type
      Returns:
      The value or null if it decodes to null
      Throws:
      IOException - If an unrecoverable error occurs
    • readValue

      @Nullable default <T> T readValue(@NonNull byte[] byteArray, @NonNull Class<T> type) throws IOException
      Read a value from the byte array for the given type.
      Type Parameters:
      T - The generic type
      Parameters:
      byteArray - The byte array
      type - The type
      Returns:
      The value or null if it decodes to null
      Throws:
      IOException - If an unrecoverable error occurs
    • readValue

      @Nullable default <T> T readValue(@NonNull String string, @NonNull Class<T> type) throws IOException
      Read a value from the given string for the given type.
      Type Parameters:
      T - The generic type
      Parameters:
      string - The string
      type - The type
      Returns:
      The value or null if it decodes to null
      Throws:
      IOException - If an unrecoverable error occurs
    • writeValueAsString

      @NonNull default <T> String writeValueAsString(@NonNull T object) throws IOException
      Write the given value as a string.
      Type Parameters:
      T - The generic type
      Parameters:
      object - The object
      Returns:
      The string
      Throws:
      IOException - If an unrecoverable error occurs
    • cloneWithFeatures

      default io.micronaut.json.JsonMapper cloneWithFeatures(io.micronaut.json.JsonFeatures features)
      Specified by:
      cloneWithFeatures in interface io.micronaut.json.JsonMapper
    • writeValueAsString

      @NonNull default <T> String writeValueAsString(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Write the given value as a string.
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type, never null
      object - The object
      Returns:
      The string
      Throws:
      IOException - If an unrecoverable error occurs
    • writeValueAsString

      @NonNull default <T> String writeValueAsString(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object, Charset charset) throws IOException
      Write the given value as a string.
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type, never null
      object - The object
      charset - The charset, never null
      Returns:
      The string
      Throws:
      IOException - If an unrecoverable error occurs
    • getDefault

      @NonNull static ObjectMapper getDefault()
      Get the default ObjectMapper instance.

      Note that this method returns an ObjectMapper that does not include any custom defined serializers or deserializers and in general should be avoided outside a few niche cases that require static access.

      Where possible you should use dependency injection to instead retrieve the ObjectMapper from the application context.

      Returns:
      The default object mapper
      Since:
      1.3.0
    • create

      @NonNull static ObjectMapper.CloseableObjectMapper create(Map<String,Object> configuration, String... packageNames)
      Creates a new custom ObjectMapper with additional beans (serializers, deserializers etc.) loaded from the given package locations.
      Parameters:
      configuration - The configuration
      packageNames - The package names
      Returns:
      The new object mapper
      Since:
      1.5.1