Hi Yeah not sure. Sounds like camel-stax could be improved to let @XmlElement override @XmlType if both are present. Though I suggest to dive into the docs of these annotations to make sure element is more specialized than xml type etc, so what you do would be a valid use-case.
If so you are welcome to log a JIRA and work on a patch. We love contributions. http://camel.apache.org/contributing.html On Tue, Dec 3, 2013 at 9:40 PM, marcelcasado <[email protected]> wrote: > I have an issue using camel split with stax (2.12.1) where the > "StAXJAXBIteratorExpression" is not able to match the xml elements to the > jaxb provided class: > > The route looks like this where splitClass is PricingProgramEnrollment > > .split(stax(splitClass, false)) > > The jaxb class with annotations looks like: > > XmlAccessorType(XmlAccessType.FIELD) > @XmlType(name = "PricingProgramEnrollmentType", propOrder = { > "userEnrollments" > }) > @XmlRootElement(name = "pricingProgramEnrollment") > public class PricingProgramEnrollment > implements Serializable > { > > The xml is : > > <?xml version="1.0" encoding="UTF-8" ?> > <pricingProgramEnrollments > xmlns="http://platform.tendrilinc.com/tnop/extension/ems" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://platform.tendrilinc.com/ems/pricing > ../../resource/extensions/pricing.xsd"> > > <pricingProgramEnrollment programName="cheap_energy1"> > > <userEnrollment accountId="test_enrollments" > effectiveDate="2013-01-01T00:00:00.000" /> > </pricingProgramEnrollment> > > </pricingProgramEnrollments> > > > Looking to the stax component code that matches the the tag names with the > provided jaxb class I see that it uses XmlType.class first for the the > matching tag name. and XmlRootElement.class if XmlType.class is not pressent > or empty string. My jaxb class has both annotations and the stax code > selects XmlType to do the matching and that does not match the > <pricingProgramEnrollment> in the xml. Is this a bug should XmlRootElement > should be the first choice? What is the purpose to match XmlType? > > public final class StAXUtil { > private static final Map<Class<?>, String> TAG_NAMES = new > LRUSoftCache<Class<?>, String>(1000); > > private StAXUtil() { > // no-op > } > > public static String getTagName(Class<?> handled) { > if (TAG_NAMES.containsKey(handled)) { > return TAG_NAMES.get(handled); > } > > XmlType xmlType = handled.getAnnotation(XmlType.class); > if (xmlType != null && xmlType.name() != null && > xmlType.name().trim().length() > 0) { > TAG_NAMES.put(handled, xmlType.name()); > return xmlType.name(); > } else { > XmlRootElement xmlRoot = > handled.getAnnotation(XmlRootElement.class); > if (xmlRoot != null && xmlRoot.name() != null && > xmlRoot.name().trim().length() > 0) { > TAG_NAMES.put(handled, xmlRoot.name()); > return xmlRoot.name(); > } > } > throw new IllegalArgumentException("XML name not found for " + > handled.getName()); > } > } > > > Thanks, > > -Marcel Casado > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Issue-using-camel-split-stax-tp5744264.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen Make your Camel applications look hawt, try: http://hawt.io
