Skip to content

Set as Union value quirks #2082

@alexdlm

Description

@alexdlm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions