palantir / palantir/conjure-java

Set as Union value quirks

Open
#2,082 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
39
Forks
49
Avg merge
8h 22m
Merged PRs (30d)
32

Description

What happened?

Union values that are sets have a few quirks. eg:

MyUnion:
  union:
    fooSet: set<Foo>

They are not implemented as LinkedHashSet, and so do not retain insertion order like conjure'd set<> fields do.
They are not immutable copies (!).
They are slightly more difficult to construct (eg MyUnion.fooSet(...) the arg must be a set).

The generated FooSetWrapper:

    @JsonTypeName("fooSet")
    private static final class FooSetWrapper implements Base {
        private final Set<Foo> value;

        @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
        private FooSetWrapper(@JsonSetter(value = "fooSet", nulls = Nulls.AS_EMPTY) @Nonnull Set<Foo> value) {
            Preconditions.checkNotNull(value, "fooSet cannot be null");
            this.value = value;
        }
        // ...

Regular conjure objects are deserialized via their builder, which initializes sets as LinkedHashSet, copies the incoming value, and then on build stores an immutable set.

I would guess this behavior extends to Maps as union members also.

What did you want to happen?

  1. Maintain insertion order like conjure fields. Probably this arg needs a @JsonDeserialize(as = LinkedHashSet.class).
  2. Do not store this.value directly, make a copy.
  3. Have additional Union creators that take Iterable like regular fields.

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 comparing the generated FooSetWrapper for MyUnion.fooSet with the regular conjure object builder behavior described in the issue. Trace the union generation entry point and determine how set and map members are handled; done means ordered, copied values and Iterable-based creators are covered for the requested union members.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.