WireJsonAdapterFactory

class WireJsonAdapterFactory @JvmOverloads constructor(typeUrlToAdapter: Map<String, ProtoAdapter<*>> = mapOf(), writeIdentityValues: Boolean = false, preservingProtoFieldNames: Boolean = false) : JsonAdapter.Factory

A JsonAdapter.Factory that allows Wire messages to be serialized and deserialized using the Moshi Json library.

Moshi moshi = new Moshi.Builder()
.add(new WireJsonAdapterFactory())
.build();

The resulting Moshi instance will be able to serialize and deserialize Wire Message types, including extensions. It ignores unknown field values. The JSON encoding is intended to be compatible with the protobuf-java-format library.

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.

Set preservingProtoFieldNames to true if you want the field names to be unchanged from their definition in the protobuf schema on JSON serialisation. If false, Wire will follow the official specification (i.e. camelCase). Note that preservingProtoFieldNames, when true, takes precedence over the jsonName option.

Constructors

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

Functions

Link copied to clipboard
open override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi): JsonAdapter<*>?
Link copied to clipboard
fun plus(adapter: ProtoAdapter<*>): WireJsonAdapterFactory

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

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

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