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.
    static @NonNull ObjectMapper
    Get the default ObjectMapper instance.
    default <T> T
    readValue(@io.micronaut.core.annotation.NonNull byte[] byteArray, @NonNull Class<T> type)
    Read a value from the byte array for the given type.
    default <T> T
    readValue(@NonNull InputStream inputStream, @NonNull Class<T> type)
    Read a value from the given input stream for the given type.
    default <T> T
    readValue(@NonNull String string, @NonNull Class<T> type)
    Read a value from the given string for the given type.
    default <T> @NonNull String
    writeValueAsString(@NonNull io.micronaut.core.type.Argument<T> type, T object)
    Write the given value as a string.
    default <T> @NonNull String
    writeValueAsString(@NonNull io.micronaut.core.type.Argument<T> type, T object, Charset charset)
    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, writeValueAsString, writeValueToTree, writeValueToTree
  • Method Details

    • readValue

      @Nullable default <T> T readValue(@NonNull @NonNull InputStream inputStream, @NonNull @NonNull Class<T> type) throws IOException
      Read a value from the given input stream for the given type.
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      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 @io.micronaut.core.annotation.NonNull byte[] byteArray, @NonNull @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 @NonNull String string, @NonNull @NonNull Class<T> type) throws IOException
      Read a value from the given string for the given type.
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      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
    • 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> @NonNull String writeValueAsString(@NonNull @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> @NonNull String writeValueAsString(@NonNull @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 @NonNull 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 @NonNull 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