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

Information about fixed attributes is being lost when generating optional getters #126

Open
RoanH opened this issue Apr 10, 2024 · 0 comments
Labels

Comments

@RoanH
Copy link
Contributor

RoanH commented Apr 10, 2024

I spotted this issue while investigating #124, but I do not have any ideas for a potential fix.

Using the same example as in the linked issue, with -Ximm-optionalgetter enabled, and based on the same XSD snippet:

<xs:element name="DecimalExtensionType">
	<xs:complexType>
		<xs:simpleContent>
			<xs:extension base="BaseType">
				<xs:attribute name="unit" fixed="s"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>
</xs:element>
<xs:simpleType name="BaseType">
	<xs:restriction base="xs:decimal">
		<xs:fractionDigits value="3"/>
	</xs:restriction>
</xs:simpleType>

Note that the code originally generated to get the unit attribute value is:

public String getUnit() {
	if (unit == null) {
		return "s";
	} else {
		return unit;
	}
}

However, since this is not a required attribute this getter is replaced with:

public Optional<String> getUnit() {
	return Optional.ofNullable(unit);
}

The default value that was intended to be returned from fixed="s" is however lost because of this. As a side note, the original getters are also generated with javadoc, which is also lost when using this plugin, but the generated javadoc comment does not contain any information that isn't in the method signature so I don't think its worth filing an issue for this.

@sabomichal sabomichal added the bug label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants