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

Generated POJO has compilation error when GraphQL type has field named "class" #994

Closed
arturshevchenko opened this issue Sep 1, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@arturshevchenko
Copy link

arturshevchenko commented Sep 1, 2022

Ability to rename field names

problem is: (getClass method)
need to rename

image

thanks

@kobylynskyi kobylynskyi added this to the 5.5.0 milestone Sep 5, 2022
@kobylynskyi kobylynskyi self-assigned this Sep 5, 2022
@kobylynskyi kobylynskyi added the enhancement New feature or request label Sep 5, 2022
@kobylynskyi
Copy link
Owner

@arturshevchenko I've made one fix to handle a field named "class", so that the generated POJO for your GraphQL type will be:

public class Ship implements java.io.Serializable {
    ...
    private String Class;

    public Ship() {
    }

    public Ship(... , String Class) {
        ...
        this.Class = Class;
    }

    ...

    public String GetClass() {
        return Class;
    }
    public void setClass(String Class) {
        this.Class = Class;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        final Ship that = (Ship) obj;
        return ...
            && Objects.equals(Class, that.Class);
    }

    @Override
    public int hashCode() {
        return Objects.hash(..., Class);
    }

    @Override
    public String toString() {
        StringJoiner joiner = new StringJoiner(", ", "{ ", " }");
        ...
        if (Class != null) {
            joiner.add("class: " + GraphQLRequestSerializer.getEntry(Class));
        }
        return joiner.toString();
    }

    public static Ship.Builder builder() {
        return new Ship.Builder();
    }

    public static class Builder {

        ...
        private String Class;

        public Builder() {
        }

        ...

        public Builder setClass(String Class) {
            this.Class = Class;
            return this;
        }


        public Ship build() {
            return new Ship(..., Class);
        }

    }
}

@kobylynskyi kobylynskyi changed the title Ability to rename field names Generated POJO has compilation error when GraphQL type has field named "class" Sep 5, 2022
@kobylynskyi
Copy link
Owner

The fix will be released in 5.5.0 soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants