Repository navigation
Conversation
Wire 7 failed when JSON set two members of one oneof for generated Java and for generated Kotlin with flat oneofs. Wire 8.0.0-alpha01 keeps the last member, because FieldBinding now calls the oneof builder method for every decoder. That rule is right for binary decoding, but Moshi and Gson share the bindings. Add FieldOrOneOfBinding.setFromJson, which assigns the member without clearing the others, so build() fails as before. Binary decoding keeps the last member. Boxed and sealed oneofs keep the last member in JSON, as in Wire 7. A null member next to a value is skipped and keeps the value.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wire 8.0.0-alpha01 keeps the last member when JSON sets two members of one oneof.
Wire 7 rejected this input for generated Java and for generated Kotlin with flat oneofs, like protobuf-java does.
The change came from #3781, which made the shared field bindings keep the last member.
That rule is right for binary decoding, but Moshi and Gson use the same bindings.
FieldOrOneOfBinding.setFromJsonnow assigns a oneof member without clearing the other members.build()then throws the sameIllegalArgumentExceptionas in Wire 7, with the same message.The Moshi and Gson adapters call it.
Binary decoding does not change, and the last member on the wire still wins.
Boxed and sealed oneofs keep the last member in JSON, as they did in Wire 7.
A
nullmember next to a value is skipped, so the value stays, in either order.The Swift runtime does not change.
Release note: Moshi and Gson fail again when JSON sets two non-null members of one oneof in generated Java or flat generated Kotlin code, as in Wire 7.