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

Having an optional<any> generates an unchecked cast #390

Open
gatesn opened this issue May 22, 2019 · 1 comment
Open

Having an optional<any> generates an unchecked cast #390

gatesn opened this issue May 22, 2019 · 1 comment

Comments

@gatesn
Copy link

gatesn commented May 22, 2019

What happened?

Defining an object like this:

MyObject:
  fields:
    myfield: optional<any>

Results in the following Java code:

    @Generated("com.palantir.conjure.java.types.BeanBuilderGenerator")
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static final class Builder {
        ...
        @JsonSetter("detail")
        public Builder detail(Optional<?> detail) {
            this.detail =
                    (Optional<Object>) Preconditions.checkNotNull(detail, "detail cannot be null");
            return this;
        }

        public Builder detail(Object detail) {
            this.detail = Optional.of(Preconditions.checkNotNull(detail, "detail cannot be null"));
            return this;
        }
    }

Where Optional<?> is cast into an Optional<Object>.

What did you want to happen?

    public static final class Builder {
        ...
        @JsonSetter("detail")
        public Builder detail(Optional<Object> detail) {
            this.detail = Preconditions.checkNotNull(detail, "detail cannot be null");
            return this;
        }
		...
    }
@iamdanfox
Copy link
Contributor

Possibly relevant PR: #9

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

2 participants