-
Notifications
You must be signed in to change notification settings - Fork 20
JaxbAnnotationIntrospector creates an element from @XmlAttribute instead of an attribute #6
Comments
I can not reproduce this with version 2.0.2 (added unit test). One difference is that I do not see that extra namespace declaration; could be because tests use Woodstox Stax implementation (not the JDK 1.6 default Sjsxp). |
I am running this as a maven project and it would appear stax-api is coming down w/ the jackson dependency. Might you try running this in maven to see if you can reproduce it there? <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>jackson-jaxb-poc</groupId> <artifactId>jackson-jaxb-poc</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> <version>2.0.2</version> <scope>compile</scope> </dependency> </dependencies> </project> |
I will try it. |
Is this issue still active? I am experiencing similar behaviour, on a very small maven module based on Java 6, using Jackson version 2.0.5 libraries. Serialized through JAXB: <jurisdiction name="Aversan" messageStandard="CeRx"/> Serialized through Jackson: <jurisdiction>
<name>Aversan</name>
<messageStandard>CeRx</messageStandard>
</jurisdiction> Object: @XmlAccessorType(value = XmlAccessType.FIELD)
public class Jurisdiction {
@XmlAttribute(name="name",required=true)
private String name;
@XmlAttribute(name="messageStandard", required=true)
private String messageStandard;
... Jackson mapping code: @Test
public void serializeXML() throws Exception {
ObjectMapper mapper = new XmlMapper();
mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
logger.info(mapper.writeValueAsString(constructSampleScenario()));
} Maven dependencies: <dependencies>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.1.4</version>
<scope>test</scope>
</dependency>
</dependencies> Thanks for the awesome library! |
Thank you for code sample: I will try to reproduce this with 2.1.0-SNAPSHOT. |
Ok, @geoffrr, I can not reproduce this issue with 2.1.0-SNAPSHOT; for me attribute annotation works with both Jackson and JAXB annotations. I can try to see if I can reproduce it with 2.0.5... |
Can not reproduce with 2.0.5 either. |
Can not reproduce, closing. Please file a new issue with unit test (and version), if still problematic with 2.1.1 or above. |
Ok: as per #6 I finally understand the issue, and this was reproducible. The issue is now solved for 2.4 (not yet released); but with earlier version, the work-around is to use |
Expected: <Individual identifier="1"><givenName>Jay</givenName><surName>Unit</surName></Individual>
Actual: <Individual xmlns=""><identifier>1</identifier><givenName>Jay</givenName><surName>Unit</surName></Individual>
}
The text was updated successfully, but these errors were encountered: