Skip to content

Commit b97ffed

Browse files
committed
Backport #333 fix
1 parent abd7a23 commit b97ffed

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

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.9.9 (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: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,20 @@ public ToXmlGenerator createGenerator(OutputStream out) throws IOException {
448448
public ToXmlGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException
449449
{
450450
// false -> we won't manage the stream unless explicitly directed to
451-
IOContext ctxt = _createContext(out, false);
451+
final IOContext ctxt = _createContext(out, false);
452452
ctxt.setEncoding(enc);
453453
return new ToXmlGenerator(ctxt,
454454
_generatorFeatures, _xmlGeneratorFeatures,
455-
_objectCodec, _createXmlWriter(out));
455+
_objectCodec, _createXmlWriter(ctxt, out));
456456
}
457457

458458
@Override
459459
public ToXmlGenerator createGenerator(Writer out) throws IOException
460460
{
461-
return new ToXmlGenerator(_createContext(out, false),
461+
final IOContext ctxt = _createContext(out, false);
462+
return new ToXmlGenerator(ctxt,
462463
_generatorFeatures, _xmlGeneratorFeatures,
463-
_objectCodec, _createXmlWriter(out));
464+
_objectCodec, _createXmlWriter(ctxt, out));
464465
}
465466

466467
@SuppressWarnings("resource")
@@ -469,10 +470,10 @@ public ToXmlGenerator createGenerator(File f, JsonEncoding enc) throws IOExcepti
469470
{
470471
OutputStream out = new FileOutputStream(f);
471472
// true -> yes, we have to manage the stream since we created it
472-
IOContext ctxt = _createContext(out, true);
473+
final IOContext ctxt = _createContext(out, true);
473474
ctxt.setEncoding(enc);
474475
return new ToXmlGenerator(ctxt, _generatorFeatures, _xmlGeneratorFeatures,
475-
_objectCodec, _createXmlWriter(out));
476+
_objectCodec, _createXmlWriter(ctxt, out));
476477
}
477478

478479
/*
@@ -580,7 +581,7 @@ protected FromXmlParser _createParser(char[] data, int offset, int len, IOContex
580581
}
581582
return xp;
582583
}
583-
584+
584585
@Override
585586
protected FromXmlParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException
586587
{
@@ -612,22 +613,22 @@ protected JsonGenerator _createGenerator(Writer out, IOContext ctxt) throws IOEx
612613
/**********************************************************************
613614
*/
614615

615-
protected XMLStreamWriter _createXmlWriter(OutputStream out) throws IOException
616+
protected XMLStreamWriter _createXmlWriter(IOContext ctxt, OutputStream out) throws IOException
616617
{
617618
XMLStreamWriter sw;
618619
try {
619-
sw = _xmlOutputFactory.createXMLStreamWriter(out, "UTF-8");
620+
sw = _xmlOutputFactory.createXMLStreamWriter(_decorate(ctxt, out), "UTF-8");
620621
} catch (XMLStreamException e) {
621622
return StaxUtil.throwAsGenerationException(e, null);
622623
}
623624
return _initializeXmlWriter(sw);
624625
}
625626

626-
protected XMLStreamWriter _createXmlWriter(Writer w) throws IOException
627+
protected XMLStreamWriter _createXmlWriter(IOContext ctxt, Writer w) throws IOException
627628
{
628629
XMLStreamWriter sw;
629630
try {
630-
sw = _xmlOutputFactory.createXMLStreamWriter(w);
631+
sw = _xmlOutputFactory.createXMLStreamWriter(_decorate(ctxt, w));
631632
} catch (XMLStreamException e) {
632633
return StaxUtil.throwAsGenerationException(e, null);
633634
}
@@ -820,4 +821,31 @@ private final static int skipSpace(InputAccessor acc, byte b) throws IOException
820821
}
821822
}
822823

824+
/*
825+
/**********************************************************
826+
/* Decorators, output
827+
/**********************************************************
828+
*/
829+
830+
protected OutputStream _decorate(IOContext ioCtxt, OutputStream out) throws IOException
831+
{
832+
if (_outputDecorator != null) {
833+
OutputStream out2 = _outputDecorator.decorate(ioCtxt, out);
834+
if (out2 != null) {
835+
return out2;
836+
}
837+
}
838+
return out;
839+
}
840+
841+
protected Writer _decorate(IOContext ioCtxt, Writer out) throws IOException
842+
{
843+
if (_outputDecorator != null) {
844+
Writer out2 = _outputDecorator.decorate(ioCtxt, out);
845+
if (out2 != null) {
846+
return out2;
847+
}
848+
}
849+
return out;
850+
}
823851
}

0 commit comments

Comments
 (0)