Skip to content

Commit

Permalink
CXFXJC-47: XJC DefaultValue plugin uses JAXBElement that does not hav…
Browse files Browse the repository at this point in the history
…e a default constructor
  • Loading branch information
reta committed Jun 7, 2024
1 parent 1d98bc4 commit df57515
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
18 changes: 17 additions & 1 deletion dv-test/src/test/resources/schemas/configuration/foo.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,21 @@
<xs:sequence>
<xs:element minOccurs="0" name="redemptionNumber" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:complexType>

<xs:element name="vehicle" type="tns:vehicle"/>
<xs:complexType name="vehicle" abstract="true"/>

<xs:complexType name="car">
<xs:complexContent>
<xs:extension base="tns:vehicle"/>
</xs:complexContent>
</xs:complexType>
<xs:element name="car" type="tns:car" substitutionGroup="tns:vehicle"/>

<xs:complexType name="trip">
<xs:sequence>
<xs:element ref="tns:vehicle"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
14 changes: 13 additions & 1 deletion dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -73,6 +76,15 @@
public class DefaultValuePlugin {

private static final Logger LOG = Logger.getLogger(DefaultValuePlugin.class.getName()); //NOPMD

// Known JAXB / JAXWS classes that do not have default constructors.
private static final Set<String> KNOWN_NO_DV_CLASSES = new HashSet<>(
Arrays.asList(
"jakarta.xml.ws.wsaddressing.W3CEndpointReference",
"jakarta.xml.bind.JAXBElement"
)
);

private boolean complexTypes;
private boolean active;

Expand Down Expand Up @@ -204,7 +216,7 @@ public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
String varName = f.getPropertyInfo().getName(false);
JFieldVar var = co.implClass.fields().get(varName);
final JType rawType = f.getRawType();
if (var != null && !"jakarta.xml.ws.wsaddressing.W3CEndpointReference".equals(rawType.fullName())) {
if (var != null && !KNOWN_NO_DV_CLASSES.contains(rawType.erasure().fullName())) {
if (rawType instanceof JClass) {
final JClass jclazz = (JClass) rawType;
if (!jclazz.isAbstract() && !jclazz.isInterface()) {
Expand Down

0 comments on commit df57515

Please sign in to comment.