Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ee417d
commit e88829a
Showing
6 changed files
with
187 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlBeanDeserializerModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.fasterxml.jackson.dataformat.xml.deser; | ||
|
||
import java.util.*; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.deser.*; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedMember; | ||
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; | ||
import com.fasterxml.jackson.dataformat.xml.util.AnnotationUtil; | ||
|
||
/** | ||
* The main reason for a modifier is to support handling of | ||
* 'wrapped' Collection types. | ||
*/ | ||
public class XmlBeanDeserializerModifier | ||
extends BeanDeserializerModifier | ||
{ | ||
@Override | ||
public List<BeanPropertyDefinition> updateProperties(DeserializationConfig config, | ||
BeanDescription beanDesc, List<BeanPropertyDefinition> propDefs) | ||
{ | ||
final AnnotationIntrospector intr = config.getAnnotationIntrospector(); | ||
int changed = 0; | ||
for (int i = 0, len = propDefs.size(); i < len; ++i) { | ||
BeanPropertyDefinition prop = propDefs.get(i); | ||
AnnotatedMember acc = prop.getAccessor(); | ||
// should not be null, but just in case: | ||
if (acc == null) { | ||
continue; | ||
} | ||
QName wrapperName = AnnotationUtil.findWrapperName(intr, acc); | ||
if (wrapperName == null) { | ||
continue; | ||
} | ||
String localName = wrapperName.getLocalPart(); | ||
if ((localName == null || localName.length() == 0) | ||
|| localName.equals(prop.getName())) { | ||
continue; | ||
} | ||
// make copy-on-write as necessary | ||
if (changed == 0) { | ||
propDefs = new ArrayList<BeanPropertyDefinition>(propDefs); | ||
} | ||
++changed; | ||
// Also, must do upcast unfortunately | ||
propDefs.set(i, prop.withName(localName)); | ||
} | ||
return propDefs; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/fasterxml/jackson/dataformat/xml/util/AnnotationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.fasterxml.jackson.dataformat.xml.util; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import com.fasterxml.jackson.databind.AnnotationIntrospector; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedMember; | ||
import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector; | ||
|
||
public class AnnotationUtil | ||
{ | ||
public static String findNamespaceAnnotation(AnnotationIntrospector ai, | ||
AnnotatedMember prop) | ||
{ | ||
for (AnnotationIntrospector intr : ai.allIntrospectors()) { | ||
if (intr instanceof XmlAnnotationIntrospector) { | ||
String ns = ((XmlAnnotationIntrospector) intr).findNamespace(prop); | ||
if (ns != null) { | ||
return ns; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static Boolean findIsAttributeAnnotation(AnnotationIntrospector ai, | ||
AnnotatedMember prop) | ||
{ | ||
for (AnnotationIntrospector intr : ai.allIntrospectors()) { | ||
if (intr instanceof XmlAnnotationIntrospector) { | ||
Boolean b = ((XmlAnnotationIntrospector) intr).isOutputAsAttribute(prop); | ||
if (b != null) { | ||
return b; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static QName findWrapperName(AnnotationIntrospector ai, AnnotatedMember prop) | ||
{ | ||
for (AnnotationIntrospector intr : ai.allIntrospectors()) { | ||
if (intr instanceof XmlAnnotationIntrospector) { | ||
QName n = ((XmlAnnotationIntrospector) intr).findWrapperElement(prop); | ||
if (n != null) { | ||
return n; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters