类 JsonProtoModule.AnySerializer

  • 所有已实现的接口:
    com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
    封闭类:
    JsonProtoModule

    protected class JsonProtoModule.AnySerializer
    extends com.fasterxml.jackson.databind.JsonSerializer<com.google.protobuf.Any>
    AnySerializer converts a ProtoBuf Any object into its JSON representation.

    This is not a canonical ProtoBuf JSON representation. Let us explain what we're trying to accomplish here:

    The Any ProtoBuf message is a type in the PB standard library that can store any other arbitrary ProtoBuf message in a type-safe way, even when the server has no knowledge of the schema of the stored message.

    It accomplishes this by storing a tuple of information: an URL-like type declaration for the stored message, and the serialized binary encoding of the stored message itself. Language specific implementations of ProtoBuf provide helper methods to encode and decode arbitrary messages into an Any object (Any.pack(Message) in Java).

    We want to expose these Any objects in the REST API because they've been introduced as part of the new GRPC interface to Conductor, but unfortunately we cannot encode them using their canonical ProtoBuf JSON encoding. According to the docs:

    The JSON representation of an `Any` value uses the regular representation of the deserialized, embedded message, with an additional field `@type` which contains the type URL. Example:

    package google.profile; message Person { string first_name = 1; string last_name = 2; } { "@type": "type.googleapis.com/google.profile.Person", "firstName": , "lastName": }

    In order to accomplish this representation, the PB-JSON encoder needs to have knowledge of all the ProtoBuf messages that could be serialized inside the Any message. This is not possible to accomplish inside the Conductor server, which is simply passing through arbitrary payloads from/to clients.

    Consequently, to actually expose the Message through the REST API, we must create a custom encoding that contains the raw data of the serialized message, as we are not able to deserialize it on the server. We simply return a dictionary with '@type' and '@value' keys, where '@type' is identical to the canonical representation, but '@value' contains a base64 encoded string with the binary data of the serialized message.

    Since all the provided Conductor clients are required to know this encoding, it's always possible to re-build the original Any message regardless of the client's language.

    {@see AnyDeserializer}

    • 嵌套类概要

      • 从类继承的嵌套类/接口 com.fasterxml.jackson.databind.JsonSerializer

        com.fasterxml.jackson.databind.JsonSerializer.None
    • 构造器概要

      构造器 
      限定符 构造器 说明
      protected AnySerializer()  
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      void serialize​(com.google.protobuf.Any value, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider provider)  
      • 从类继承的方法 com.fasterxml.jackson.databind.JsonSerializer

        acceptJsonFormatVisitor, getDelegatee, handledType, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId
    • 构造器详细资料

      • AnySerializer

        protected AnySerializer()
    • 方法详细资料

      • serialize

        public void serialize​(com.google.protobuf.Any value,
                              com.fasterxml.jackson.core.JsonGenerator jgen,
                              com.fasterxml.jackson.databind.SerializerProvider provider)
                       throws IOException
        指定者:
        serialize 在类中 com.fasterxml.jackson.databind.JsonSerializer<com.google.protobuf.Any>
        抛出:
        IOException