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

Issue 395 : add option to generate default-attribute-value in java class #396

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

laurentschoelens
Copy link
Collaborator

Fixes #395

This will generate defaultValue in field for attributes if specified by plugin's all option.

@mattrpav
Copy link
Collaborator

mattrpav commented Sep 25, 2023

Is this plugin needed? IIRC, if you specify a default value on an attribute (also assumes 'optional'), the jaxb-maven-plugin generates a lazy initialized value:

public boolean isEnabled() {
    if (enabled == null) {
        return true;
    } else {
        return enabled;
    }
}

@laurentschoelens
Copy link
Collaborator Author

Is this plugin needed? IIRC, if you specify a default value on an attribute (also assumes 'optional'), the jaxb-maven-plugin generates a lazy initialized value:

public boolean isEnabled() {
    if (enabled == null) {
        return true;
    } else {
        return enabled;
    }
}

Not by default but we have a problem on attributes default value and equals startegy.

For example : the equals strategy in plugins does getter / getter comparison with "isSet" attribute on fields. If not done, and having two objects enabled = true on first, and enabled = null on the second, it will return equals = false even if "isEnabled" will both return true and will be marshalled the same way.

Main goal is in hyperjaxb but should also apply on other projects as well (even if attributes are not widely used in my own projects)

@mattrpav mattrpav closed this Sep 25, 2023
@mattrpav mattrpav reopened this Sep 25, 2023
Copy link
Collaborator

@mattrpav mattrpav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattrpav mattrpav merged commit 2e2c620 into highsource:master Sep 25, 2023
@mattrpav mattrpav deleted the jt-395 branch September 25, 2023 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Plugins] Default value option to fix defaultValue for attributes
2 participants