Class ProtoJsonUtils

java.lang.Object
org.a2aproject.sdk.grpc.utils.ProtoJsonUtils

public final class ProtoJsonUtils extends Object
Protobuf-to-JSON serialization without HTML escaping.

JsonFormat.printer() delegates to Gson's JsonWriter which HTML-escapes <, >, and & by default. This utility removes those escape sequences via HtmlEscapeUtils.removeHtmlEscaping(String).

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    toJson(com.google.protobuf.util.JsonFormat.Printer printer, @Nullable com.google.protobuf.MessageOrBuilder proto)
    Serializes a protobuf message to JSON using the supplied printer, then removes HTML escaping.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toJson

      public static String toJson(com.google.protobuf.util.JsonFormat.Printer printer, @Nullable com.google.protobuf.MessageOrBuilder proto) throws com.google.protobuf.InvalidProtocolBufferException
      Serializes a protobuf message to JSON using the supplied printer, then removes HTML escaping.
      Parameters:
      printer - the configured JsonFormat.Printer (callers choose options such as alwaysPrintFieldsWithNoPresence() or omittingInsignificantWhitespace())
      proto - the protobuf message to serialize, or null
      Returns:
      JSON string without HTML-escaped characters, or empty string if proto is null
      Throws:
      com.google.protobuf.InvalidProtocolBufferException