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

OutputDecorator not called with XmlMapper #333

Closed
ndionisi opened this issue Feb 19, 2019 · 7 comments
Closed

OutputDecorator not called with XmlMapper #333

ndionisi opened this issue Feb 19, 2019 · 7 comments
Milestone

Comments

@ndionisi
Copy link

ndionisi commented Feb 19, 2019

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.

@cowtowncoder
Copy link
Member

That is quite possible: I fixed this, I think, for 3.0 (master) and possibly for 2.10.

Which version is this with?

@ndionisi
Copy link
Author

Sorry, should have mentionned the version. Got the issue in 2.9.8

cowtowncoder added a commit that referenced this issue Feb 26, 2019
@cowtowncoder cowtowncoder added 2.10 and removed 2.9 labels Feb 26, 2019
@cowtowncoder cowtowncoder added this to the 2.10 milestone Feb 26, 2019
@cowtowncoder cowtowncoder changed the title OutputDecorator not called with XmlMapper OutputDecorator not called with XmlMapper Feb 26, 2019
@cowtowncoder cowtowncoder added 2.9 and removed 2.10 labels Feb 26, 2019
@cowtowncoder cowtowncoder modified the milestones: 2.10, 2.9.9 Feb 26, 2019
cowtowncoder added a commit that referenced this issue Feb 26, 2019
@cowtowncoder
Copy link
Member

Ok, I think I fixed this in 2.9 -- tests only added in 2.10 due to some problems in reusing tests from other formats (where fix is only in 2.10; configuration of decorators changes between 2.9/2.10 wrt recommended method).

So, 2.9.9 should have the fix; 2.10.0 as well.

@ndionisi
Copy link
Author

Just tested it in 2.9.9, it actually works, thanks a lot!

@ndionisi
Copy link
Author

Quick question, do you plan a release of 2.9.9 soon?
Thanks

@cowtowncoder
Copy link
Member

Released now.

@ndionisi
Copy link
Author

Great, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants