Skip to content

Commit

Permalink
Add a failing test for #354
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 7, 2019
1 parent c7a2478 commit c801a96
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* abstract out all irrelevant details, and to expose equivalent of flat token
* stream with no "fluff" tokens (comments, processing instructions, mixed
* content) all of which is just to simplify
* actual higher-level conversion to JSON tokens
* actual higher-level conversion to JSON tokens.
*<p>
* Beyond initial idea there are also couple of other detours like ability
* to "replay" some tokens, add virtual wrappers (ironically to support "unwrapped"
* array values), and to unroll "Objects" into String values in some cases.
*/
public class XmlTokenStream
{
Expand Down Expand Up @@ -146,7 +150,7 @@ protected void setFormatFeatures(int f) {

// DEBUGGING
/*
public int next() throws IOException
public int next() throws XMLStreamException
{
int n = next0();
switch (n) {
Expand Down Expand Up @@ -270,6 +274,10 @@ protected void skipAttributes()
}
}

/**
* Helper method called by XML String deserializer to concatenate textual contents
* contained in logical "Object": mostly just to skip attribute values.
*/
protected String convertToString() throws XMLStreamException
{
// only applicable to cases where START_OBJECT was induced by attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public boolean equals(Object o)
return true;
}
}

protected static class StringBean
{
public String text;
Expand All @@ -118,7 +118,7 @@ public String toString() {
return "\""+text+"\"";
}
}

/**
* Simple wrapper around String type, usually to test value
* conversions or wrapping
Expand All @@ -131,7 +131,7 @@ public StringWrapper(String value) {
str = value;
}
}

protected static class IntWrapper {
public int i;

Expand All @@ -141,7 +141,6 @@ public IntWrapper(int value) {
}
}

// since 2.9.6
public static class Point {
public int x, y;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static class Issue167Bean {
/**********************************************************
*/

private final XmlMapper MAPPER = new XmlMapper();
private final XmlMapper MAPPER = newMapper();

public void testSimpleStringElement() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.fasterxml.jackson.dataformat.xml.failing;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;

public class XsiNil354Test extends XmlTestBase
{
protected static class DoubleWrapper {
public Double d;

public DoubleWrapper() { }
public DoubleWrapper(Double value) {
d = value;
}
}

private final XmlMapper MAPPER = newMapper();

public void testWithDoubleAsNull() throws Exception
{
DoubleWrapper bean = MAPPER.readValue(
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='true'></DoubleWrapper>",
DoubleWrapper.class);
assertNotNull(bean);
assertNull(bean.d);
}

public void testWithDoubleAsNonNull() throws Exception
{
DoubleWrapper bean = MAPPER.readValue(
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='false'>0.25</DoubleWrapper>",
DoubleWrapper.class);
assertNotNull(bean);
assertEquals(Double.valueOf(0.25), bean.d);
}
}

0 comments on commit c801a96

Please sign in to comment.