-
-
Notifications
You must be signed in to change notification settings - Fork 231
Closed
Milestone
Description
OutputDecorator
seems to be ignored on XmlMapper
.
With a (JSON) ObjectMapper
, the following test passes:
@Test
public void json_objectMapper_should_use_decorator() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.getFactory().setOutputDecorator(new OutputDecorator() {
@Override
public OutputStream decorate(IOContext ctxt, OutputStream out) throws IOException {
out.write("DECORATOR".getBytes(StandardCharsets.UTF_8));
return out;
}
@Override
public Writer decorate(IOContext ctxt, Writer w) throws IOException {
w.write("DECORATOR");
return w;
}
});
assertThat(objectMapper.writeValueAsString("value")).isEqualTo("DECORATOR\"value\"");
}
But with an XmlMapper
, the following test fails:
@Test
public void xml_objectMapper_should_use_decorator() throws Exception {
ObjectMapper objectMapper = new XmlMapper();
objectMapper.getFactory().setOutputDecorator(new OutputDecorator() {
@Override
public OutputStream decorate(IOContext ctxt, OutputStream out) throws IOException {
out.write("DECORATOR".getBytes(StandardCharsets.UTF_8));
return out;
}
@Override
public Writer decorate(IOContext ctxt, Writer w) throws IOException {
w.write("DECORATOR");
return w;
}
});
assertThat(objectMapper.writeValueAsString("value")).isEqualTo("DECORATOR<String>value</String>");
}
with the following error:
org.junit.ComparisonFailure:
Expected :"DECORATOR<String>value</String>"
Actual :"<String>value</String>"
According to the source code, it seems that the XmlFactory
never calls its _decorate()
method.
Artus2b and obourgain
Metadata
Metadata
Assignees
Labels
No labels