From df575153802edbaa453c79ed218af280b1578625 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 6 Jun 2024 21:35:50 -0400 Subject: [PATCH] CXFXJC-47: XJC DefaultValue plugin uses JAXBElement that does not have a default constructor --- .../resources/schemas/configuration/foo.xsd | 18 +++++++++++++++++- .../apache/cxf/xjc/dv/DefaultValuePlugin.java | 14 +++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dv-test/src/test/resources/schemas/configuration/foo.xsd b/dv-test/src/test/resources/schemas/configuration/foo.xsd index bc0e0ec3..dfa9b2bb 100644 --- a/dv-test/src/test/resources/schemas/configuration/foo.xsd +++ b/dv-test/src/test/resources/schemas/configuration/foo.xsd @@ -147,5 +147,21 @@ - + + + + + + + + + + + + + + + + + diff --git a/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java b/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java index 2128a8a3..7c65fcb3 100644 --- a/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java +++ b/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java @@ -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; @@ -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 KNOWN_NO_DV_CLASSES = new HashSet<>( + Arrays.asList( + "jakarta.xml.ws.wsaddressing.W3CEndpointReference", + "jakarta.xml.bind.JAXBElement" + ) + ); + private boolean complexTypes; private boolean active; @@ -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()) {