Class ProtobufMapper

java.lang.Object
io.micronaut.serde.protobuf.ProtobufMapper
All Implemented Interfaces:
io.micronaut.json.JsonMapper, ObjectMapper

@Singleton @Bean(typed=ProtobufMapper.class) public final class ProtobufMapper extends Object implements ObjectMapper
An ObjectMapper that reads and writes the Protocol Buffers binary wire format.

Unlike the JSON and BSON mappers, this one is not self-describing: a payload can only be read into a concrete type whose properties carry ProtoField numbers. Reading into JsonNode or Object is therefore not supported.

This is a prototype. Its bean is exposed only as ProtobufMapper, so it cannot be selected as the application's JSON mapper; inject it by its concrete type.

Since:
3.2
  • Constructor Details

    • ProtobufMapper

      @Inject public ProtobufMapper(SerdeRegistry registry, @Nullable SerdeConfiguration serdeConfiguration)
      Default constructor.
      Parameters:
      registry - The serde registry
      serdeConfiguration - The serde configuration, if one is available
  • Method Details

    • getSerdeRegistry

      public SerdeRegistry getSerdeRegistry()
      Description copied from interface: ObjectMapper
      Returns the SerdeRegistry used by this object mapper, if possible.
      Specified by:
      getSerdeRegistry in interface ObjectMapper
      Returns:
      The serde registry
    • cloneWithViewClass

      public io.micronaut.json.JsonMapper cloneWithViewClass(Class<?> viewClass)
      Specified by:
      cloneWithViewClass in interface io.micronaut.json.JsonMapper
    • getStreamConfig

      public io.micronaut.json.JsonStreamConfig getStreamConfig()
      Specified by:
      getStreamConfig in interface io.micronaut.json.JsonMapper
    • writeValueAsBytes

      public <T> byte[] writeValueAsBytes(io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Specified by:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • writeValueAsBytes

      public byte[] writeValueAsBytes(@Nullable Object object) throws IOException
      Specified by:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • writeValue

      public <T> void writeValue(OutputStream outputStream, io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • writeValue

      public void writeValue(OutputStream outputStream, @Nullable Object object) throws IOException
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • readValue

      public <T> @Nullable T readValue(byte[] byteArray, io.micronaut.core.type.Argument<T> type) throws IOException
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • readValue

      public <T> @Nullable T readValue(InputStream inputStream, io.micronaut.core.type.Argument<T> type) throws IOException
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • writeValueToTree

      public <T> io.micronaut.json.tree.JsonNode writeValueToTree(io.micronaut.core.type.Argument<T> type, @Nullable T value) throws IOException
      Specified by:
      writeValueToTree in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • writeValueToTree

      public io.micronaut.json.tree.JsonNode writeValueToTree(@Nullable Object value) throws IOException
      Specified by:
      writeValueToTree in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • readValueFromTree

      public <T> @Nullable T readValueFromTree(io.micronaut.json.tree.JsonNode tree, io.micronaut.core.type.Argument<T> type) throws IOException
      Specified by:
      readValueFromTree in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • createReactiveParser

      public org.reactivestreams.Processor<byte[], io.micronaut.json.tree.JsonNode> createReactiveParser(Consumer<org.reactivestreams.Processor<byte[], io.micronaut.json.tree.JsonNode>> onSubscribe, boolean streamArray)
      Specified by:
      createReactiveParser in interface io.micronaut.json.JsonMapper