Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set as Union value quirks #2082

Open
alexdlm opened this issue Aug 7, 2023 · 0 comments
Open

Set as Union value quirks #2082

alexdlm opened this issue Aug 7, 2023 · 0 comments

Comments

@alexdlm
Copy link

alexdlm commented Aug 7, 2023

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant