Class ProtobufJsonTranscoder

java.lang.Object
io.micronaut.protobuf.json.ProtobufJsonTranscoder

@Singleton public class ProtobufJsonTranscoder extends Object
Utility class for handling Protobuf message serialization and deserialization to/from JSON.
  • Constructor Details

    • ProtobufJsonTranscoder

      public ProtobufJsonTranscoder()
      Constructs a new instance of ProtobufJsonTranscoder.
      This constructor initializes the JSON printer and parser for handling serialization and deserialization of Protobuf messages to and from JSON. The JSON printer is configured to include default value fields in the resulting JSON and to sort map keys for deterministic output.
  • Method Details

    • toJson

      @NonNull public @NonNull String toJson(@NonNull @NonNull com.google.protobuf.Message message)
      Converts a Protobuf message to JSON string.
      Parameters:
      message - The Protobuf message to convert
      Returns:
      JSON string representation
      Throws:
      ProtobufTranscodingException - if serialization fails
    • fromJson

      @NonNull public <T extends com.google.protobuf.Message> T fromJson(@NonNull @NonNull String jsonBody, @NonNull @NonNull Class<T> messageType)
      Creates a Protobuf message from JSON string.
      Type Parameters:
      T - The type of Protobuf message
      Parameters:
      jsonBody - The JSON string to parse
      messageType - The Protobuf message class
      Returns:
      The constructed Protobuf message
      Throws:
      ProtobufTranscodingException - if deserialization fails