Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test and fix for issue #84 #85

Merged
merged 2 commits into from
Dec 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -160,6 +160,11 @@ protected void serializeFields(Object bean, JsonGenerator jgen0, SerializerProvi
if (prop != null) { // can have nulls in filtered list
prop.serializeAsField(bean, xgen, provider);
}
// Reset to avoid next value being written as unwrapped,
// for example when property is suppressed
if (i == textIndex) {
xgen.setNextIsUnwrapped(false);
}
}
if (_anyGetterWriter != null) {
_anyGetterWriter.getAndSerialize(bean, xgen, provider);
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fasterxml.jackson.dataformat.xml.unwrapped;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;

public class TestXmlText extends XmlTestBase{
@JsonPropertyOrder({"first","second"})
class Data{
@JacksonXmlText
public String first;
public String second;
public Data(String first, String second) {
this.first = first;
this.second = second;
}
}

private final XmlMapper MAPPER = new XmlMapper();
{ // easier for eye, uncomment for testing
// MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
}

public void testXmlTextWithSuppressedValue() throws Exception {
MAPPER.setSerializationInclusion(Include.NON_EMPTY);
String xml = MAPPER.writeValueAsString(new Data("","second"));
String expectedXml = "<Data><second>second</second></Data>";
assertEquals(expectedXml, xml);
}
}