Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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);
Expand Down
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);
}
}