Skip to content

Commit 78fbb04

Browse files
committed
Fix #333
1 parent bfb3c1d commit 78fbb04

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ Yury Vasyutinskiy (Falland@github)
3131
* Contributed #232: Implement `writeRawValue` in `ToXmlGenerator`
3232
(2.9.0)
3333

34+
Nelson Dionisi (ndionisi@github)
35+
36+
* Reported #333: `OutputDecorator` not called with `XmlMapper`
37+
(2.10.0)

release-notes/VERSION-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-xml
44
= Releases
55
------------------------------------------------------------------------
66

7+
2.10.0 (not yet released)
8+
9+
#333: `OutputDecorator` not called with `XmlMapper`
10+
(reported by Nelson D)
11+
712
2.9.8 (15-Dec-2018)
813

914
#270: Add support for `writeBinary()` with `InputStream` to `ToXMLGenerator`

src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactory.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,19 +481,20 @@ public ToXmlGenerator createGenerator(OutputStream out) throws IOException {
481481
public ToXmlGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException
482482
{
483483
// false -> we won't manage the stream unless explicitly directed to
484-
IOContext ctxt = _createContext(out, false);
484+
final IOContext ctxt = _createContext(out, false);
485485
ctxt.setEncoding(enc);
486486
return new ToXmlGenerator(ctxt,
487487
_generatorFeatures, _xmlGeneratorFeatures,
488-
_objectCodec, _createXmlWriter(out));
488+
_objectCodec, _createXmlWriter(ctxt, out));
489489
}
490490

491491
@Override
492492
public ToXmlGenerator createGenerator(Writer out) throws IOException
493493
{
494-
return new ToXmlGenerator(_createContext(out, false),
494+
final IOContext ctxt = _createContext(out, false);
495+
return new ToXmlGenerator(ctxt,
495496
_generatorFeatures, _xmlGeneratorFeatures,
496-
_objectCodec, _createXmlWriter(out));
497+
_objectCodec, _createXmlWriter(ctxt, out));
497498
}
498499

499500
@SuppressWarnings("resource")
@@ -502,10 +503,10 @@ public ToXmlGenerator createGenerator(File f, JsonEncoding enc) throws IOExcepti
502503
{
503504
OutputStream out = new FileOutputStream(f);
504505
// true -> yes, we have to manage the stream since we created it
505-
IOContext ctxt = _createContext(out, true);
506+
final IOContext ctxt = _createContext(out, true);
506507
ctxt.setEncoding(enc);
507508
return new ToXmlGenerator(ctxt, _generatorFeatures, _xmlGeneratorFeatures,
508-
_objectCodec, _createXmlWriter(out));
509+
_objectCodec, _createXmlWriter(ctxt, out));
509510
}
510511

511512
/*
@@ -645,22 +646,22 @@ protected JsonGenerator _createGenerator(Writer out, IOContext ctxt) throws IOEx
645646
/**********************************************************************
646647
*/
647648

648-
protected XMLStreamWriter _createXmlWriter(OutputStream out) throws IOException
649+
protected XMLStreamWriter _createXmlWriter(IOContext ctxt, OutputStream out) throws IOException
649650
{
650651
XMLStreamWriter sw;
651652
try {
652-
sw = _xmlOutputFactory.createXMLStreamWriter(out, "UTF-8");
653+
sw = _xmlOutputFactory.createXMLStreamWriter(_decorate(ctxt, out), "UTF-8");
653654
} catch (XMLStreamException e) {
654655
return StaxUtil.throwAsGenerationException(e, null);
655656
}
656657
return _initializeXmlWriter(sw);
657658
}
658659

659-
protected XMLStreamWriter _createXmlWriter(Writer w) throws IOException
660+
protected XMLStreamWriter _createXmlWriter(IOContext ctxt, Writer w) throws IOException
660661
{
661662
XMLStreamWriter sw;
662663
try {
663-
sw = _xmlOutputFactory.createXMLStreamWriter(w);
664+
sw = _xmlOutputFactory.createXMLStreamWriter(_decorate(ctxt, w));
664665
} catch (XMLStreamException e) {
665666
return StaxUtil.throwAsGenerationException(e, null);
666667
}
@@ -853,4 +854,31 @@ private final static int skipSpace(InputAccessor acc, byte b) throws IOException
853854
}
854855
}
855856

857+
/*
858+
/**********************************************************
859+
/* Decorators, output
860+
/**********************************************************
861+
*/
862+
863+
protected OutputStream _decorate(IOContext ioCtxt, OutputStream out) throws IOException
864+
{
865+
if (_outputDecorator != null) {
866+
OutputStream out2 = _outputDecorator.decorate(ioCtxt, out);
867+
if (out2 != null) {
868+
return out2;
869+
}
870+
}
871+
return out;
872+
}
873+
874+
protected Writer _decorate(IOContext ioCtxt, Writer out) throws IOException
875+
{
876+
if (_outputDecorator != null) {
877+
Writer out2 = _outputDecorator.decorate(ioCtxt, out);
878+
if (out2 != null) {
879+
return out2;
880+
}
881+
}
882+
return out;
883+
}
856884
}

src/test/java/com/fasterxml/jackson/dataformat/xml/misc/StreamingDecoratorsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fasterxml.jackson.dataformat.xml.misc;
22

33
import java.io.*;
4-
import java.util.*;
54

65
import com.fasterxml.jackson.annotation.JsonRootName;
76
import com.fasterxml.jackson.dataformat.xml.*;

0 commit comments

Comments
 (0)