Class MapperMediaTypeCodec

java.lang.Object
io.micronaut.json.codec.MapperMediaTypeCodec
All Implemented Interfaces:
MediaTypeCodec
Direct Known Subclasses:
JacksonMediaTypeCodec, JsonMediaTypeCodec

public abstract class MapperMediaTypeCodec extends Object implements MediaTypeCodec
A MediaTypeCodec for JsonMapper based implementations.
Since:
1.3.0
Author:
Graeme Rocher, svishnyakov
  • Field Details

  • Constructor Details

    • MapperMediaTypeCodec

      public MapperMediaTypeCodec(BeanProvider<JsonMapper> mapperProvider, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType)
      Parameters:
      mapperProvider - To read/write JSON
      applicationConfiguration - The common application configurations
      codecConfiguration - The configuration for the codec
      mediaType - Client request/response media type
    • MapperMediaTypeCodec

      public MapperMediaTypeCodec(BeanProvider<JsonMapper> mapperProvider, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType, @Nullable @Nullable List<MediaType> additionalTypes)
      Parameters:
      mapperProvider - To read/write JSON
      applicationConfiguration - The common application configurations
      codecConfiguration - The configuration for the codec
      mediaType - Client request/response media type
      additionalTypes - Additional Media Types
    • MapperMediaTypeCodec

      public MapperMediaTypeCodec(JsonMapper mapper, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType)
      Parameters:
      mapper - To read/write JSON
      applicationConfiguration - The common application configurations
      codecConfiguration - The configuration for the codec
      mediaType - Client request/response media type
  • Method Details

    • getJsonMapper

      public JsonMapper getJsonMapper()
      Returns:
      The object mapper
    • cloneWithFeatures

      public MapperMediaTypeCodec cloneWithFeatures(JsonFeatures features)
      Create a copy of this codec with the given features. Should not be extended, extend cloneWithMapper(io.micronaut.json.JsonMapper) instead.
      Parameters:
      features - The features to apply.
      Returns:
      A new codec with the features applied, leaving this codec unchanged.
    • cloneWithViewClass

      public final MapperMediaTypeCodec cloneWithViewClass(Class<?> viewClass)
    • cloneWithMapper

      protected abstract MapperMediaTypeCodec cloneWithMapper(JsonMapper mapper)
    • getMediaTypes

      public Collection<MediaType> getMediaTypes()
      Specified by:
      getMediaTypes in interface MediaTypeCodec
      Returns:
      The media type of the codec
    • supportsType

      public boolean supportsType(Class<?> type)
      Description copied from interface: MediaTypeCodec
      Whether the codec can decode the given type.
      Specified by:
      supportsType in interface MediaTypeCodec
      Parameters:
      type - The type
      Returns:
      True if it can
    • decode

      public <T> T decode(Argument<T> type, InputStream inputStream) throws CodecException
      Description copied from interface: MediaTypeCodec
      Decode the given type from the given InputStream.
      Specified by:
      decode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type
      inputStream - The input stream
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be decoded
    • decode

      public <T> T decode(Argument<T> type, JsonNode node) throws CodecException
      Decodes the given JSON node.
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type
      node - The Json Node
      Returns:
      The decoded object
      Throws:
      CodecException - When object cannot be decoded
    • decode

      public <T> T decode(Argument<T> type, ByteBuffer<?> buffer) throws CodecException
      Description copied from interface: MediaTypeCodec
      Decode the given type from the given buffer. Implementations optimized to handle ByteBuffer instances should override this method.
      Specified by:
      decode in interface MediaTypeCodec
      Type Parameters:
      T - The decoded type
      Parameters:
      type - The type
      buffer - the buffer
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be decoded
    • decode

      public <T> T decode(Argument<T> type, byte[] bytes) throws CodecException
      Description copied from interface: MediaTypeCodec
      Decode the given type from the given bytes.
      Specified by:
      decode in interface MediaTypeCodec
      Type Parameters:
      T - The decoded type
      Parameters:
      type - The type
      bytes - The bytes
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be decoded
    • decode

      public <T> T decode(Argument<T> type, String data) throws CodecException
      Description copied from interface: MediaTypeCodec
      Decode the given type from the given bytes.
      Specified by:
      decode in interface MediaTypeCodec
      Type Parameters:
      T - The decoded type
      Parameters:
      type - The type
      data - The data as a string
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be decoded
    • encode

      public <T> void encode(T object, OutputStream outputStream) throws CodecException
      Description copied from interface: MediaTypeCodec
      Encode the given type to the given OutputStream.
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      object - The object to encode
      outputStream - The output stream
      Throws:
      CodecException - When the result cannot be encoded
    • encode

      public <T> void encode(Argument<T> type, T object, OutputStream outputStream) throws CodecException
      Description copied from interface: MediaTypeCodec
      Encode the given type to the given OutputStream.
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type including any generics and/or metadata.
      object - The object to encode
      outputStream - The output stream
      Throws:
      CodecException - When the result cannot be encoded
    • encode

      public <T> byte[] encode(T object) throws CodecException
      Description copied from interface: MediaTypeCodec
      Encode the given type returning the object as a byte[].
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      object - The object to encode
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be encoded
    • encode

      public <T> byte[] encode(Argument<T> type, T object) throws CodecException
      Description copied from interface: MediaTypeCodec
      Encode the given type returning the object as a byte[].
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type including any generics and/or metadata
      object - The object to encode
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be encoded
    • encode

      public <T, B> ByteBuffer<B> encode(T object, ByteBufferFactory<?,B> allocator) throws CodecException
      Description copied from interface: MediaTypeCodec
      Encode the given type returning the object as a ByteBuffer.
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      B - The buffer type
      Parameters:
      object - The object to encode
      allocator - The allocator
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be encoded
    • encode

      public <T, B> ByteBuffer<B> encode(Argument<T> type, T object, ByteBufferFactory<?,B> allocator) throws CodecException
      Description copied from interface: MediaTypeCodec
      Encode the given type returning the object as a ByteBuffer.
      Specified by:
      encode in interface MediaTypeCodec
      Type Parameters:
      T - The generic type
      B - The buffer type
      Parameters:
      type - The type including any generics and/or metadata
      object - The object to encode
      allocator - The allocator
      Returns:
      The decoded result
      Throws:
      CodecException - When the result cannot be encoded