Example usage for com.google.gson.protobuf ProtoTypeAdapter ProtoTypeAdapter

List of usage examples for com.google.gson.protobuf ProtoTypeAdapter ProtoTypeAdapter

Introduction

In this page you can find the example usage for com.google.gson.protobuf ProtoTypeAdapter ProtoTypeAdapter.

Prototype

ProtoTypeAdapter

Source Link

Usage

From source file:com.google.devtools.kythe.util.JsonUtil.java

License:Open Source License

/**
 * Registers type adapters for Java protobuf types (including ByteStrings and byte[]) that matches
 * Go's JSON encoding/decoding.//from   ww w  .  jav a  2 s  .  com
 */
public static GsonBuilder registerProtoTypes(GsonBuilder builder) {
    return builder.registerTypeHierarchyAdapter(ProtocolMessageEnum.class, new ProtoEnumTypeAdapter())
            .registerTypeHierarchyAdapter(GeneratedMessage.class, new ProtoTypeAdapter())
            .registerTypeHierarchyAdapter(ByteString.class, new ByteStringTypeAdapter())
            .registerTypeAdapter(byte[].class, new ByteArrayTypeAdapter());
}

From source file:com.google.shipshape.util.rpc.Protocol.java

License:Open Source License

/** Returns a {@link Gson} capable of en/decoding {@link Protocol} messages. */
public static Gson constructGson(GsonBuilder builder) {
    if (builder == null) {
        builder = new GsonBuilder();
    }/* www .  ja v  a 2  s.  com*/
    return builder.registerTypeAdapter(Error.class, new ErrorTypeAdapter())
            .registerTypeAdapter(Request.class, new RequestTypeAdapter())
            .registerTypeAdapter(Response.class, new ResponseTypeAdapter())
            .registerTypeAdapter(Method.Info.class, new MethodInfoSerializer())
            .registerTypeAdapter(Version.class, new VersionTypeAdapter())
            .registerTypeHierarchyAdapter(ProtocolMessageEnum.class, new ProtoEnumTypeAdapter())
            .registerTypeHierarchyAdapter(GeneratedMessage.class, new ProtoTypeAdapter())
            .registerTypeHierarchyAdapter(ByteString.class, new ByteStringTypeAdapter())
            .registerTypeAdapter(byte[].class, new ByteArrayTypeAdapter()).create();
}