Add preservingProtoFieldNames option#3521
Conversation
As discussed on square#2452, the upstream Google protobuf libraries (e.g. `JsonFormat`) can be configured to serialize with the unmodified field names from the proto files. Wire also supports this capability in Swift (https://github.com/square/wire/blob/ca1e09e297f96c52b4615f75e95780be0b10eeb7/wire-runtime-swift/src/main/swift/Codable/CodingUserInfoKey%2BWire.swift#L48-L53) but not in Java. Adding a `preservingProtoFieldNames` option to `WireJsonAdapterFactory` (Moshi) and `WireTypeAdapterFactory` (Gson) allows Wire's JSON implementation to be configured for field name preservation as well.
|
@oldergod the tests are failing because adding the second boolean parameter is an ABI break. I can modify |
oldergod
left a comment
There was a problem hiding this comment.
Let's dump the api ./gradlew apiDump and push. I think it's fine since we have the jmvoverloads
| ) | ||
| } | ||
|
|
||
| private val ALL_TYPES_PROTO2_JSON get() = loadJson("all_types_proto2.json") |
There was a problem hiding this comment.
Can you put them all back in the companion object?
There was a problem hiding this comment.
They need to be outside the companion object because loadJson now depends on the value of jsonLibrary.preservingProtoFieldNames, and jsonLibrary is a lateinit var (which is also why there's a get() on the val)
|
Very sweet. Thank you |
As discussed on #2452, the upstream Google protobuf libraries (e.g.
JsonFormat) can be configured to serialize with the unmodified field names from the proto files. Wire also supports this capability in Swift (wire/wire-runtime-swift/src/main/swift/Codable/CodingUserInfoKey+Wire.swift
Lines 48 to 53 in ca1e09e
Adding a
preservingProtoFieldNamesoption toWireJsonAdapterFactory(Moshi) andWireTypeAdapterFactory(Gson) allows Wire's JSON implementation to be configured for field name preservation as well.