[
https://issues.apache.org/jira/browse/CXF-3131?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932885#action_12932885
]
Andreas Gudian commented on CXF-3131:
-------------------------------------
My guess is, that the reason is the following code in
org.apache.cxf.xjc.dv.DefaultValuePlugin:
{code:title=org.apache.cxf.xjc.dv.DefaultValuePlugin.java}
// line 135
if (xsType != null && xsType.isComplexType() &&
containsDefaultValue(outline, f)) {
String varName = f.getPropertyInfo().getName(false);
JFieldVar var = co.implClass.fields().get(varName);
if (var != null) {
co.implClass.removeField(var);
JFieldVar newVar =
co.implClass.field(var.mods().getValue(),
var.type(),
var.name(),
JExpr._new(f.getRawType()));
newVar.javadoc().append(var.javadoc());
}
}
{code}
The annotation from the old field var is not copied to the new field newVar.
Perhaps I'm missing something, but wouldn't be the following change just do the
trick?
{code:title=org.apache.cxf.xjc.dv.DefaultValuePlugin.java - Proposed Fix}
// line 135
if (xsType != null && xsType.isComplexType() &&
containsDefaultValue(outline, f)) {
String varName = f.getPropertyInfo().getName(false);
JFieldVar var = co.implClass.fields().get(varName);
if (var != null) {
var.init(JExpr._new(f.getRawType()));
}
}
{code}
Can anyone check this, please?
Thanks!
> CXF XCJ DV Plugin removes XmlElement Annotation from Fields
> -----------------------------------------------------------
>
> Key: CXF-3131
> URL: https://issues.apache.org/jira/browse/CXF-3131
> Project: CXF
> Issue Type: Bug
> Components: Tooling
> Affects Versions: 2.3.0
> Reporter: Andreas Gudian
> Priority: Critical
>
> Using the XJC default value plugin (org.apache.cxf.xjcplugins:cxf-xjc-dv)
> removes the @XmlElement(name=...) annotation from fields where it adds a
> default value.
> For example, see the following XSD fragment:
> {code:xml}
> <xs:complexType name="TypeA">
> <xs:sequence>
> <xs:element name="Customer"
> type="tns:customerTypeWithDefaultValuesInside" />
> </xs:sequence>
> </xs:complexType>
> {code}
> *Without* dv, the following code is generated:
> {code:title=TypeA.java}
> ...
> @XmlElement(name = "Customer", required = true)
> protected CustomerTypeWithDefaultValuesInside customer;
> ...
> {code}
> Now, *With* -X-dv, the following code is generated:
> {code:title=TypeA.java}
> ...
> /*
> *
> */
> protected CustomerTypeWithDefaultValuesInside customer = new
> CustomerTypeWithDefaultValuesInside();
> ...
> {code}
> With the XmlElement annotation missing, the XML instance generated during
> marshalling contains an element {{<customer>}}, instead of {{<Customer>}} -
> which does not correspond to the definition in the XSD and is therefor
> invalid.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.