WireTypeAdapterFactory

class WireTypeAdapterFactory @JvmOverloads constructor(typeUrlToAdapter: Map<String, ProtoAdapter<*>> = mapOf(), writeIdentityValues: Boolean = false) : TypeAdapterFactory

A TypeAdapterFactory that allows Wire messages to be serialized and deserialized using the GSON Json library. To create a Gson instance that works with Wire, use the com.google.gson.GsonBuilder interface:

Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new WireTypeAdapterFactory())
.create();

The resulting Gson instance will be able to serialize and deserialize any Wire Message type, including extensions and unknown field values. The JSON encoding is intended to be compatible with the protobuf-java-format library. Note that version 1.2 of that API has a bug in the way it serializes unknown fields, so we use our own approach for this case.

In Proto3, if a field is set to its default (or identity) value, it will be omitted in the JSON-encoded data. Set writeIdentityValues to true if you want Wire to always write values, including default ones.

Constructors

Link copied to clipboard
constructor(typeUrlToAdapter: Map<String, ProtoAdapter<*>> = mapOf(), writeIdentityValues: Boolean = false)

Functions

Link copied to clipboard
open override fun <T> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>?
Link copied to clipboard
fun plus(adapter: ProtoAdapter<*>): WireTypeAdapterFactory

Returns a new WireTypeAdapterFactory that can encode the messages for adapter if they're used with AnyMessage.

fun plus(adapters: List<ProtoAdapter<*>>): WireTypeAdapterFactory

Returns a new WireJsonAdapterFactory that can encode the messages for adapters if they're used with AnyMessage.