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
8d52926
commit 742524a
Showing
4 changed files
with
132 additions
and
7 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
36 changes: 36 additions & 0 deletions
36
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/DefaultTyping325Test.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,36 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class DefaultTyping325Test extends XmlTestBase | ||
{ | ||
static class Simple { | ||
protected List<String> list; | ||
|
||
public List<String> getList( ) { return list; } | ||
public void setList(List<String> l) { list = l; } | ||
} | ||
|
||
public void testCanSerialize() throws IOException | ||
{ | ||
ObjectMapper mapper = objectMapperBuilder() | ||
.build(); | ||
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_OBJECT); | ||
|
||
// construct test object | ||
Simple s = new Simple(); | ||
s.setList(Arrays.asList("foo", "bar")); | ||
|
||
String doc = mapper.writeValueAsString(s); | ||
System.err.println("DOC: "+doc); | ||
Simple result = mapper.readValue(doc, Simple.class); | ||
assertNotNull(result.list); | ||
assertEquals(2, result.list.size()); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/FailingNamespace311Test.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,80 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import javax.xml.stream.*; | ||
|
||
import com.ctc.wstx.stax.WstxInputFactory; | ||
import com.ctc.wstx.stax.WstxOutputFactory; | ||
import com.fasterxml.jackson.databind.*; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.*; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
// for [dataformat-xml#311] | ||
public class FailingNamespace311Test extends XmlTestBase | ||
{ | ||
@JacksonXmlRootElement(localName = "new") | ||
static class Bean { | ||
@JacksonXmlProperty(isAttribute = true) | ||
public String source="ECOM"; | ||
public Member member; | ||
|
||
public Bean(int id, String name) { | ||
this.member=new Member(id, name); | ||
} | ||
|
||
public Member getMember() { | ||
return member; | ||
} | ||
} | ||
|
||
static 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; | ||
} | ||
} | ||
|
||
public void testIssue311() throws Exception { | ||
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); | ||
|
||
XmlMapper mapper = new XmlMapper(xmlInputFactory); | ||
mapper.enable(SerializationFeature.INDENT_OUTPUT); | ||
|
||
XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(System.out); | ||
|
||
startDocument(writer); | ||
Bean bean=new Bean(1, "Dude"); | ||
mapper.writeValue(writer, bean); | ||
endDocument(writer); | ||
} | ||
|
||
protected void startDocument(XMLStreamWriter writer) 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(XMLStreamWriter writer) throws XMLStreamException { | ||
writer.writeCharacters("\n"); | ||
writer.writeEndDocument(); | ||
} | ||
} |
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