Skip to content

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

@RoanH

Description

@RoanH

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions