Class ProtoJson


  • public final class ProtoJson
    extends java.lang.Object
    Converts proto messages to canonical JSON format. The canonical JSON has the fields sorted and white space stripped. This is to make sure that exactly the same string is produced which is important when it is signed or hash is computed.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <M extends com.google.protobuf.Message>
      M
      fromJson​(java.lang.String json, com.google.protobuf.Message.Builder blank)
      Gets message from JSON.
      static <M extends com.google.protobuf.Message>
      M
      fromJson​(java.lang.String json, com.google.protobuf.Message.Builder blank, boolean ignoreUnknownFields)
      Gets message from JSON.
      static java.lang.String toJson​(com.google.protobuf.Message message)
      Converts message to JSON.
      • Methods inherited from class java.lang.Object

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

      • toJson

        public static java.lang.String toJson​(com.google.protobuf.Message message)
        Converts message to JSON.
        Parameters:
        message - message to convert
        Returns:
        JSON value
      • fromJson

        public static <M extends com.google.protobuf.Message> M fromJson​(java.lang.String json,
                                                                         com.google.protobuf.Message.Builder blank)
        Gets message from JSON. Unknown fields will not be ignored in parsing.
        Type Parameters:
        M - Message type
        Parameters:
        json - JSON value
        blank - builder
        Returns:
        Message instance
      • fromJson

        public static <M extends com.google.protobuf.Message> M fromJson​(java.lang.String json,
                                                                         com.google.protobuf.Message.Builder blank,
                                                                         boolean ignoreUnknownFields)
        Gets message from JSON.
        Type Parameters:
        M - Message type
        Parameters:
        json - JSON value
        blank - builder
        ignoreUnknownFields - ignore unknown fields
        Returns:
        Message instance