Created
September 27, 2018 12:30
-
-
Save fredrik-rambris/bcf07f98a7a3fe2a0a606be950fa0fad to your computer and use it in GitHub Desktop.
Test case for possible bug in JacksonXML
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
package com.rambris; | |
import com.ctc.wstx.stax.WstxInputFactory; | |
import com.ctc.wstx.stax.WstxOutputFactory; | |
import com.fasterxml.jackson.databind.SerializationFeature; | |
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | |
import javax.xml.stream.XMLInputFactory; | |
import javax.xml.stream.XMLOutputFactory; | |
import javax.xml.stream.XMLStreamException; | |
import javax.xml.stream.XMLStreamWriter; | |
import java.io.IOException; | |
public class App { | |
protected XMLStreamWriter writer; | |
protected XmlMapper mapper; | |
public App() throws XMLStreamException { | |
XMLInputFactory xmlInputFactory = new WstxInputFactory(); | |
XMLOutputFactory xmlOutputFactory = new WstxOutputFactory(); | |
/* Setting this to true makes the application run but does not write namespace */ | |
xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); | |
mapper=new XmlMapper(xmlInputFactory); | |
mapper.enable(SerializationFeature.INDENT_OUTPUT); | |
writer=xmlOutputFactory.createXMLStreamWriter(System.out); | |
} | |
protected void startDocument() throws XMLStreamException { | |
writer.writeStartDocument("utf-8", "1.0"); | |
writer.writeCharacters("\n"); | |
writer.setDefaultNamespace("http://eClub.Schemas.ImportContact"); | |
writer.writeStartElement("contacts"); | |
writer.writeDefaultNamespace( "http://eClub.Schemas.ImportContact"); | |
writer.writeCharacters("\n"); | |
} | |
protected void endDocument() throws XMLStreamException { | |
writer.writeCharacters("\n"); | |
writer.writeEndDocument(); | |
} | |
public void test() throws XMLStreamException, IOException { | |
startDocument(); | |
Bean bean=new Bean(1, "Dude"); | |
mapper.writeValue(writer, bean); | |
endDocument(); | |
} | |
public static void main( String[] args ) throws Exception { | |
App app=new App(); | |
app.test(); | |
} | |
} |
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
package com.rambris; | |
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | |
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | |
@JacksonXmlRootElement(localName = "new") | |
public class Bean { | |
@JacksonXmlProperty(isAttribute = true) | |
private String source="ECOM"; | |
private Member member; | |
public Bean(int id, String name) { | |
this.member=new Member(id, name); | |
} | |
public Member getMember() { | |
return member; | |
} | |
public class Member { | |
private final int id; | |
private final String name; | |
public Member(int id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
public int getId() { | |
return id; | |
} | |
public String getName() { | |
return name; | |
} | |
} | |
} |
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
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-databind</artifactId> | |
<version>2.9.7</version> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.dataformat</groupId> | |
<artifactId>jackson-dataformat-xml</artifactId> | |
<version>2.9.7</version> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.woodstox</groupId> | |
<artifactId>woodstox-core</artifactId> | |
<version>5.0.3</version> | |
</dependency> |
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
<?xml version='1.0' encoding='utf-8'?> | |
<contacts xmlns="http://eClub.Schemas.ImportContact"> | |
<new source="ECOM"> | |
<member> | |
<id>1</id> | |
<name>Dude</name> | |
</member> | |
</new> | |
</contacts> |
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
<?xml version='1.0' encoding='utf-8'?> | |
<contacts> | |
<new source="ECOM"> | |
<member> | |
<id>1</id> | |
<name>Dude</name> | |
</member> | |
</new> | |
</contacts> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment