-
Notifications
You must be signed in to change notification settings - Fork 20
@XmlElement type and @XmlJavaTypeAdapter annotations #26
Comments
To summarize the problem PS. I noticed also that instead of using best match approach the code that handles |
@TuomasKiviaho Thank you for digging into this! You are probably wrt first match. I can have a look to see if it'd be easy enough to try to find a better match. |
@dn2k-dev I guess I do not quite follow what |
@TuomasKiviaho Actually, I am not quite sure what you mean there. |
@cowtowncoder Oops. I meant to say
|
@cowtowncoder you are right the type is redundant or not needed here at all. |
@dn2k-dev I am sure there are remaining issues, and handling of package-level annotations is bit of a pain as it is something Jackson was never designed to support (but it is something JAXB heavily promotes). Having said all that, it seems to me that it should be possible to support all of this within @TuomasKiviaho I think that solving the problem with non-optimal adapter would be relatively easy to solve, if there was a simple test case to reproduce it. I had a look at code itself, and resolution is relatively compact, but does indeed stop at first match. Plus I wasn't 100% sure whether test used was even correct ( |
@cowtowncoder Adapter consideration is missing also from
JaxbAnnotationIntrospector
private XmlAdapter<Object,Object> findAdapter(Annotated am, boolean forSerialization,
Class<?> type)
{
// First of all, are we looking for annotations for class?
// if (am instanceof AnnotatedClass) {
// return findAdapterForClass((AnnotatedClass) am, forSerialization);
// }
...
}
@Override
public List<NamedType> findSubtypes(Annotated a)
{
// No package/superclass defaulting (only used with fields, methods)
XmlElements elems = findAnnotation(XmlElements.class, a, false, false, false);
ArrayList<NamedType> result = null;
if (elems != null) {
result = new ArrayList<NamedType>();
for (XmlElement elem : elems.value()) {
String name = elem.name();
if (MARKER_FOR_DEFAULT.equals(name)) name = null;
Class<?> type = elem.type();
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(type, this, null);
XmlAdapter<Object, Object> adapter = findAdapter(ac, true, type);
if (adapter != null) {
type = findAdapterBoundType(adapter);
}
result.add(new NamedType(type, name));
}
} else {
XmlElementRefs elemRefs = findAnnotation(XmlElementRefs.class, a, false, false, false);
if (elemRefs != null) {
result = new ArrayList<NamedType>();
for (XmlElementRef elemRef : elemRefs.value()) {
Class<?> refType = elemRef.type();
// only good for types other than JAXBElement (which is XML based)
if (!JAXBElement.class.isAssignableFrom(refType)) {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(refType, this, null);
XmlAdapter<Object, Object> adapter = findAdapter(ac, true, refType);
if (adapter != null) {
refType = findAdapterBoundType(adapter);
}
// [JACKSON-253] first consider explicit name declaration
String name = elemRef.name();
if (name == null || MARKER_FOR_DEFAULT.equals(name)) {
XmlRootElement rootElement = (XmlRootElement) refType.getAnnotation(XmlRootElement.class);
if (rootElement != null) {
name = rootElement.name();
}
}
if (name == null || MARKER_FOR_DEFAULT.equals(name)) {
name = Introspector.decapitalize(refType.getSimpleName());
}
result.add(new NamedType(refType, name));
}
}
}
}
// [Issue#1] check @XmlSeeAlso as well.
/* 17-Aug-2012, tatu: But wait! For structured type, what we really is
* value (content) type!
* If code below does not make full (or any) sense, do not despair -- it
* is wrong. Yet it works. The call sequence before we get here is mangled,
* its logic twisted... but as Dire Straits put it: "That ain't working --
* that's The Way You Do It!"
*/
XmlSeeAlso ann = a.getAnnotation(XmlSeeAlso.class);
if (ann != null) {
if (result == null) {
result = new ArrayList<NamedType>();
}
for (Class<?> cls : ann.value()) {
result.add(new NamedType(cls));
}
}
return result;
} |
@TuomasKiviaho since projected has moved, this would need to move to: https://github.com/FasterXML/jackson-modules-base/issues Do you think you could re-file it over there? The reason I am asking you is that I think you have better understanding of the situation and could give better up-to-date description than I can. |
Hi.
On one of my classes I got this annotation for JAXB:
in the package-info.java I defined an adapter to convert string to CustomObject and CustomObject to string
When i tried to get JSON string from object using:
I get an exception:
Caused by: java.lang.IllegalArgumentException: Illegal concrete-type annotation for method 'getName': class java.lang.String not a super-type of (declared) class com.copmany.CustomObject
for more information:
FasterXML/jackson-jaxrs-providers#36
I found in method: public Class<?> findSerializationType(Annotated a)
In file: JaxbAnnotationInspector.java
that you dont look for @XmlJavaTypeAdapter at the package level at all...
but this isn't right....
the @XmlJavaTypeAdapter in the package level always need to be checked because it very important for custom objects that returns many times. ( like custom UUIDs class)
Full stack trace:
The text was updated successfully, but these errors were encountered: