square / square/wire

Add support oneOf enum key

Open
#2,401 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

Now in generated classes with oneOf field require is using for checking not null only one element.
Proto:

  oneof location_oneof {
    ProtoBaseStationLocation BaseStationLocationInfo = 6;
    ProtoDeviceLocation DeviceLocationInfo = 7;
  }

Generated code in Wire:

  init {
    require(countNonNull(BaseStationLocationInfo, DeviceLocationInfo) <= 1) {
      "At most one of BaseStationLocationInfo, DeviceLocationInfo may be non-null"
    }
  }

But some servers send responses with oneOfField for choosing result as in protobuf lib. And wire failes decoding because countNotNull > 1.
Genereted code in ProtoBuf:

private int locationOneofCase_ = 0;
    private java.lang.Object locationOneof_;
    public enum LocationOneofCase
        implements com.google.protobuf.Internal.EnumLite {
      BASESTATIONLOCATIONINFO(6),
      DEVICELOCATIONINFO(7),
      LOCATIONONEOF_NOT_SET(0);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Wire's oneof generation and decoding logic, using the shown generated Kotlin and protobuf Java representations as the comparison. Done means Wire can decode responses containing multiple oneof fields when servers use the protobuf-style oneof case representation, without failing the non-null check.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.