Comments (4)
Looking at this again, if the type
attribute is missing from an annotation, it's expected to be derived from the property type itself. Now, I don't know codemodel that much (and am having trouble debugging it to inspect it in greater details), but I assume this should rather be fixed like so:
jfv.annotations().stream()
.filter(jau -> Utils.isXmlElements(jau.getAnnotationClass()))
.map(jau -> (JAnnotationArrayMember) jau.getAnnotationMembers().get("value"))
.flatMap(value -> value.annotations().stream())
.forEach(anno -> {
JAnnotationValue type = anno.getAnnotationMembers().get("type");
if (type != null) {
handleXmlElement(outline, directClasses, type);
} else {
if (jfv.type().elementType() != null) { // Adapt this for List<T>. This only works for T[].
handleXmlElement(outline, directClasses, jfv.type().elementType());
}
}
});
And changing the final argument to handleXmlElement
to a JGenerable
from jaxb-visitor.
@Warpten thanks for reporting this. Can you provide a full example so I can add it as a test case?
I'm wondering if the else should invoke the addIfDirectClass
helper like so:
JClass elementType = (JClass) jfv.type().elementType();
List<JClass> typeParameters = elementType.getTypeParameters();
if (typeParameters != null && typeParameters.get(0) != null) {
addIfDirectClass(directClasses, typeParameters.get(0));
} else {
addIfDirectClass(directClasses, elementType);
}
It would help to have some schemas and different settings to test with.
from jaxb-visitor.
Sorry, I forgot about this.
A test case should be as simple as reusing the codehaus
unit test with the sample XSD file I provided (it's self sufficient). Alternatively, I think this triggers as soon as the base type in an inheritance layout is prsent in a <xs:choice>
's possible value types:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DerivedA" type="DerivedA"/>
<xs:element name="BaseType" type="BaseType"/>
<xs:element name="TypeList" type="TypeList"/>
<xs:element name="DerivedD" type="DerivedD" />
<xs:complexType name="TypeList">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="DerivedA"/>
<xs:element ref="BaseType"/>
<xs:element ref="DerivedD"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BaseType" />
<xs:complexType name="DerivedA">
<xs:complexContent>
<xs:extension base="BaseType">
<xs:sequence />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="DerivedD">
<xs:complexContent>
<xs:extension base="BaseType">
<xs:sequence />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
This is enough to trigger the NPE when used with the basic-codehaus
test.
As far as fixing this goes, I also tried this approach:
jfv.annotations().stream()
.filter(jau -> Utils.isXmlElements(jau.getAnnotationClass()))
.map(jau -> (JAnnotationArrayMember) jau.getAnnotationMembers().get("value"))
.flatMap(value -> value.annotations().stream())
.forEach(anno -> {
JAnnotationValue type = anno.getAnnotationMembers().get("type");
if (type != null) {
handleXmlElement(outline, directClasses, type);
} else {
JClass jcs = (JClass) jfv.type();
if (Objects.equals(outline.getCodeModel().ref(List.class), jcs.erasure())) {
JClass elementType = jcs.getTypeParameters().get(0);
handleXmlElement(outline, directClasses, elementType);
} else {
handleXmlElement(outline, directClasses, jcs);
}
}
});
But I don't know that it is correct.
from jaxb-visitor.
@Warpten I added your schema as a test case and took the simple approach of checking for the type and then handling an array or collection. Thanks for the report and suggestions.
from jaxb-visitor.
Related Issues (16)
- visitor / depth first trasverser with custom class bindings HOT 16
- NullPointerException when running visitor plugin HOT 4
- Duplicate methods in visitor HOT 6
- Possible issue with generated DepthFirstSearchTraverserImpl? HOT 10
- Problems with TraversingVisitor implementation for custom classes HOT 4
- Typed IDREF(S) properties lead to Compile Errors
- Limit Visitor to a Particaular type HOT 5
- DepthFirstTraverserImpl follows IDREFS
- package is not compatible with jdk 10 HOT 4
- jaxb-visitor is not compatible with maven-jaxb2-plugin 0.14.0 HOT 4
- update to the latest maven testing framework HOT 1
- allow option to only emit interfaces only HOT 1
- support both Jakarta and JDK 8 style dependencies
- add support for a param for visit and traverse generation
- some Jakarta namespaces aren't being checked for legacy flag
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxb-visitor.