-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update release notes wrt #360; test clean up
- Loading branch information
1 parent
9148d9e
commit 4dedfd7
Showing
5 changed files
with
78 additions
and
36 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
36 changes: 36 additions & 0 deletions
36
src/test/java/com/fasterxml/jackson/dataformat/xml/ser/CustomSerializerTest.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.ser; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class CustomSerializerTest extends XmlTestBase | ||
{ | ||
@SuppressWarnings("serial") | ||
static class CustomSerializer extends StdScalarSerializer<String> | ||
{ | ||
public CustomSerializer() { super(String.class); } | ||
|
||
@Override | ||
public void serialize(String value, JsonGenerator jgen, | ||
SerializerProvider provider) throws IOException { | ||
jgen.writeString("custom:"+value); | ||
} | ||
} | ||
|
||
// for [dataformat-xml#41] | ||
public void testCustomSerializer() throws Exception | ||
{ | ||
SimpleModule module = new SimpleModule(); | ||
module.addSerializer(String.class, new CustomSerializer()); | ||
final XmlMapper mapper = XmlMapper.builder() | ||
.addModule(module) | ||
.build(); | ||
assertEquals("<String>custom:foo</String>", mapper.writeValueAsString("foo")); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/fasterxml/jackson/dataformat/xml/ser/NullSerializationTest.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,33 @@ | ||
package com.fasterxml.jackson.dataformat.xml.ser; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class NullSerializationTest extends XmlTestBase | ||
{ | ||
static class WrapperBean<T> | ||
{ | ||
public T value; | ||
|
||
public WrapperBean() { } | ||
public WrapperBean(T v) { value = v; } | ||
} | ||
|
||
// [dataformat-xml#360] | ||
public void testNil() throws IOException | ||
{ | ||
final XmlMapper mapper = XmlMapper.builder() | ||
.configure(ToXmlGenerator.Feature.WRITE_NULLS_AS_XSI_NIL, true) | ||
.build(); | ||
|
||
// First, map in a general wrapper | ||
assertEquals("<WrapperBean><value xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\"/></WrapperBean>", | ||
mapper.writeValueAsString(new WrapperBean<>(null))); | ||
|
||
// and then as root -- not sure what it should exactly look like but... | ||
String xml = mapper.writeValueAsString(null); | ||
assertEquals("<null xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\"/>", xml); | ||
} | ||
} |
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