From 3676be9373f7e39b7e3556a8a5e9f601c7167ae2 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 29 Nov 2024 19:10:45 -0800 Subject: [PATCH] Implement #687: refactor XML read/write Feature names (#688) --- release-notes/VERSION | 2 + .../jackson/dataformat/xml/XmlFactory.java | 12 +- .../dataformat/xml/XmlFactoryBuilder.java | 30 ++-- .../jackson/dataformat/xml/XmlMapper.java | 20 +-- .../dataformat/xml/XmlReadFeature.java | 86 +++++++++++ .../dataformat/xml/XmlWriteFeature.java | 132 ++++++++++++++++ .../dataformat/xml/deser/FromXmlParser.java | 98 +----------- .../dataformat/xml/deser/XmlTokenStream.java | 13 +- .../dataformat/xml/ser/ToXmlGenerator.java | 146 ++---------------- .../xml/ser/XmlSerializationContext.java | 3 +- .../dataformat/xml/FeatureDefaultsTest.java | 7 +- .../dataformat/xml/MapperCopyTest.java | 4 +- .../xml/deser/EmptyBeanDeser318Test.java | 3 +- .../xml/deser/EmptyStringValueTest.java | 3 +- .../xml/deser/NullConversionsSkipTest.java | 5 +- .../dataformat/xml/deser/XsiNilBasicTest.java | 5 +- .../dataformat/xml/deser/XsiTypeReadTest.java | 7 +- .../xml/lists/EmptyListDeserTest.java | 3 +- .../xml/lists/StringListRoundtripTest.java | 4 +- .../xml/node/JsonNodeSerUnwrapped441Test.java | 6 +- .../dataformat/xml/ser/TestSerialization.java | 9 +- .../xml/ser/TestSerializationManual.java | 3 +- .../xml/ser/TestXmlDeclaration.java | 5 +- .../xml/ser/XmlPrettyPrinterTest.java | 9 +- .../xml/ser/XsiNilSerializationTest.java | 3 +- .../dataformat/xml/ser/XsiTypeWriteTest.java | 5 +- .../dataformat/xml/stream/XmlParserTest.java | 5 +- .../xml/stream/XmlTokenStreamTest.java | 16 +- 28 files changed, 327 insertions(+), 317 deletions(-) create mode 100644 src/main/java/tools/jackson/dataformat/xml/XmlReadFeature.java create mode 100644 src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java diff --git a/release-notes/VERSION b/release-notes/VERSION index 93d57e15b..4a954ed8f 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -10,4 +10,6 @@ Version: 3.x (for earlier see VERSION-2.x) #25: `ACCEPT_EMPTY_STRING_AS_NULL_OBJECT` not honored in xml module for attributes (reported by Morten-Olav H) #540: Rename "com.fasterxml.jackson" -> "tools.jackson" +#687: JSTEP-8: rename `FromXmlParser.Feature` as `XmlReadFeature`, + `ToXmlGenerator.Feature` as `XmlWriteFeature` - Add `XmlMapper.shared()` diff --git a/src/main/java/tools/jackson/dataformat/xml/XmlFactory.java b/src/main/java/tools/jackson/dataformat/xml/XmlFactory.java index ebf613c8e..7b5433f4e 100644 --- a/src/main/java/tools/jackson/dataformat/xml/XmlFactory.java +++ b/src/main/java/tools/jackson/dataformat/xml/XmlFactory.java @@ -43,13 +43,13 @@ public class XmlFactory * Bitfield (set of flags) of all parser features that are enabled * by default. */ - final static int DEFAULT_XML_PARSER_FEATURE_FLAGS = FromXmlParser.Feature.collectDefaults(); + final static int DEFAULT_XML_PARSER_FEATURE_FLAGS = XmlReadFeature.collectDefaults(); /** * Bitfield (set of flags) of all generator features that are enabled * by default. */ - final static int DEFAULT_XML_GENERATOR_FEATURE_FLAGS = ToXmlGenerator.Feature.collectDefaults(); + final static int DEFAULT_XML_GENERATOR_FEATURE_FLAGS = XmlWriteFeature.collectDefaults(); /* /********************************************************************** @@ -301,13 +301,13 @@ public boolean canUseSchema(FormatSchema schema) { } @Override - public Class getFormatReadFeatureType() { - return FromXmlParser.Feature.class; + public Class getFormatReadFeatureType() { + return XmlReadFeature.class; } @Override - public Class getFormatWriteFeatureType() { - return ToXmlGenerator.Feature.class; + public Class getFormatWriteFeatureType() { + return XmlWriteFeature.class; } @Override diff --git a/src/main/java/tools/jackson/dataformat/xml/XmlFactoryBuilder.java b/src/main/java/tools/jackson/dataformat/xml/XmlFactoryBuilder.java index 7e5bb0196..5f5c01cdb 100644 --- a/src/main/java/tools/jackson/dataformat/xml/XmlFactoryBuilder.java +++ b/src/main/java/tools/jackson/dataformat/xml/XmlFactoryBuilder.java @@ -8,8 +8,6 @@ import tools.jackson.core.StreamReadConstraints; import tools.jackson.core.StreamWriteConstraints; import tools.jackson.core.base.DecorableTSFactory.DecorableTSFBuilder; -import tools.jackson.dataformat.xml.deser.FromXmlParser; -import tools.jackson.dataformat.xml.ser.ToXmlGenerator; /** * {@link tools.jackson.core.TSFBuilder} @@ -162,65 +160,65 @@ public XmlNameProcessor xmlNameProcessor() { // // // Parser features - public XmlFactoryBuilder enable(FromXmlParser.Feature f) { + public XmlFactoryBuilder enable(XmlReadFeature f) { _formatParserFeatures |= f.getMask(); return _this(); } - public XmlFactoryBuilder enable(FromXmlParser.Feature first, FromXmlParser.Feature... other) { + public XmlFactoryBuilder enable(XmlReadFeature first, XmlReadFeature... other) { _formatParserFeatures |= first.getMask(); - for (FromXmlParser.Feature f : other) { + for (XmlReadFeature f : other) { _formatParserFeatures |= f.getMask(); } return _this(); } - public XmlFactoryBuilder disable(FromXmlParser.Feature f) { + public XmlFactoryBuilder disable(XmlReadFeature f) { _formatParserFeatures &= ~f.getMask(); return _this(); } - public XmlFactoryBuilder disable(FromXmlParser.Feature first, FromXmlParser.Feature... other) { + public XmlFactoryBuilder disable(XmlReadFeature first, XmlReadFeature... other) { _formatParserFeatures &= ~first.getMask(); - for (FromXmlParser.Feature f : other) { + for (XmlReadFeature f : other) { _formatParserFeatures &= ~f.getMask(); } return _this(); } - public XmlFactoryBuilder configure(FromXmlParser.Feature f, boolean state) { + public XmlFactoryBuilder configure(XmlReadFeature f, boolean state) { return state ? enable(f) : disable(f); } // // // Generator features - public XmlFactoryBuilder enable(ToXmlGenerator.Feature f) { + public XmlFactoryBuilder enable(XmlWriteFeature f) { _formatGeneratorFeatures |= f.getMask(); return _this(); } - public XmlFactoryBuilder enable(ToXmlGenerator.Feature first, ToXmlGenerator.Feature... other) { + public XmlFactoryBuilder enable(XmlWriteFeature first, XmlWriteFeature... other) { _formatGeneratorFeatures |= first.getMask(); - for (ToXmlGenerator.Feature f : other) { + for (XmlWriteFeature f : other) { _formatGeneratorFeatures |= f.getMask(); } return _this(); } - public XmlFactoryBuilder disable(ToXmlGenerator.Feature f) { + public XmlFactoryBuilder disable(XmlWriteFeature f) { _formatGeneratorFeatures &= ~f.getMask(); return _this(); } - public XmlFactoryBuilder disable(ToXmlGenerator.Feature first, ToXmlGenerator.Feature... other) { + public XmlFactoryBuilder disable(XmlWriteFeature first, XmlWriteFeature... other) { _formatGeneratorFeatures &= ~first.getMask(); - for (ToXmlGenerator.Feature f : other) { + for (XmlWriteFeature f : other) { _formatGeneratorFeatures &= ~f.getMask(); } return _this(); } - public XmlFactoryBuilder configure(ToXmlGenerator.Feature f, boolean state) { + public XmlFactoryBuilder configure(XmlWriteFeature f, boolean state) { return state ? enable(f) : disable(f); } diff --git a/src/main/java/tools/jackson/dataformat/xml/XmlMapper.java b/src/main/java/tools/jackson/dataformat/xml/XmlMapper.java index 22beff79b..c3d3ce673 100644 --- a/src/main/java/tools/jackson/dataformat/xml/XmlMapper.java +++ b/src/main/java/tools/jackson/dataformat/xml/XmlMapper.java @@ -181,21 +181,21 @@ public Builder activateDefaultTyping(PolymorphicTypeValidator ptv, DefaultTyping /****************************************************************** */ - public Builder enable(FromXmlParser.Feature... features) { - for (FromXmlParser.Feature f : features) { + public Builder enable(XmlReadFeature... features) { + for (XmlReadFeature f : features) { _formatReadFeatures |= f.getMask(); } return this; } - public Builder disable(FromXmlParser.Feature... features) { - for (FromXmlParser.Feature f : features) { + public Builder disable(XmlReadFeature... features) { + for (XmlReadFeature f : features) { _formatReadFeatures &= ~f.getMask(); } return this; } - public Builder configure(FromXmlParser.Feature feature, boolean state) + public Builder configure(XmlReadFeature feature, boolean state) { if (state) { _formatReadFeatures |= feature.getMask(); @@ -205,21 +205,21 @@ public Builder configure(FromXmlParser.Feature feature, boolean state) return this; } - public Builder enable(ToXmlGenerator.Feature... features) { - for (ToXmlGenerator.Feature f : features) { + public Builder enable(XmlWriteFeature... features) { + for (XmlWriteFeature f : features) { _formatWriteFeatures |= f.getMask(); } return this; } - public Builder disable(ToXmlGenerator.Feature... features) { - for (ToXmlGenerator.Feature f : features) { + public Builder disable(XmlWriteFeature... features) { + for (XmlWriteFeature f : features) { _formatWriteFeatures &= ~f.getMask(); } return this; } - public Builder configure(ToXmlGenerator.Feature feature, boolean state) + public Builder configure(XmlWriteFeature feature, boolean state) { if (state) { _formatWriteFeatures |= feature.getMask(); diff --git a/src/main/java/tools/jackson/dataformat/xml/XmlReadFeature.java b/src/main/java/tools/jackson/dataformat/xml/XmlReadFeature.java new file mode 100644 index 000000000..333eba5ea --- /dev/null +++ b/src/main/java/tools/jackson/dataformat/xml/XmlReadFeature.java @@ -0,0 +1,86 @@ +package tools.jackson.dataformat.xml; + +import javax.xml.XMLConstants; + +import tools.jackson.core.FormatFeature; +import tools.jackson.core.JsonToken; + +/** + * Enumeration that defines all togglable features for XML parsers. + *

+ * NOTE: in Jackson 2.x this was named {@code FromXmlParser.Feature}. + */ +public enum XmlReadFeature implements FormatFeature +{ + /** + * Feature that enables automatic conversion of incoming "xsi:type" + * (where "type" is the local name and "xsi" prefix is bound to URI + * {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}), + * into Jackson simple Property Name of {@code "xsi:type"}. + * This is usually needed to read content written using + * matching {@code ToXmlGenerator.Feature#AUTO_DETECT_XSI_TYPE} feature, + * usually used for Polymorphic handling where it is difficult + * to specify proper XML Namespace for type identifier. + *

+ * Default setting is {@code false}. + */ + AUTO_DETECT_XSI_TYPE(false), + + /** + * Feature that indicates whether empty XML elements + * (both empty tags like {@code } and {@code } + * (with no intervening cdata) + * are exposed as {@link JsonToken#VALUE_NULL}) or not. + * If they are not + * returned as `null` tokens, they will be returned as {@link JsonToken#VALUE_STRING} + * tokens with textual value of "" (empty String). + *

+ * NOTE: in Jackson 2.x, only "true" empty tags were affected, not split ones. + * With 3.x both cases handled uniformly. + *

+ * Default setting is {@code false}. + */ + EMPTY_ELEMENT_AS_NULL(false), + + /** + * Feature that indicates whether XML Schema Instance attribute + * {@code xsi:nil} will be processed automatically -- to indicate {@code null} + * values -- or not. + * If enabled, {@code xsi:nil} attribute on any XML element will mark such + * elements as "null values" and any other attributes or child elements they + * might have to be ignored. If disabled this attribute will be exposed like + * any other attribute. + *

+ * Default setting is {@code true}. + */ + PROCESS_XSI_NIL(true), + + ; + + private final boolean _defaultState; + private final int _mask; + + /** + * Method that calculates bit set (flags) of all features that + * are enabled by default. + */ + public static int collectDefaults() + { + int flags = 0; + for (XmlReadFeature f : values()) { + if (f.enabledByDefault()) { + flags |= f.getMask(); + } + } + return flags; + } + + private XmlReadFeature(boolean defaultState) { + _defaultState = defaultState; + _mask = (1 << ordinal()); + } + + @Override public boolean enabledByDefault() { return _defaultState; } + @Override public int getMask() { return _mask; } + @Override public boolean enabledIn(int flags) { return (flags & getMask()) != 0; } +} diff --git a/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java b/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java new file mode 100644 index 000000000..780f775d3 --- /dev/null +++ b/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java @@ -0,0 +1,132 @@ +package tools.jackson.dataformat.xml; + +import javax.xml.XMLConstants; + +import tools.jackson.core.FormatFeature; + +/** + * Enumeration that defines all togglable extra XML-specific features. + *

+ * NOTE: in Jackson 2.x this was named {@code ToXmlGenerator.Feature}. + */ +public enum XmlWriteFeature implements FormatFeature +{ + /** + * Feature that controls whether XML declaration should be written before + * when generator is initialized (true) or not (false) + */ + WRITE_XML_DECLARATION(false), + + /** + * Feature that controls whether output should be done as XML 1.1; if so, + * certain aspects may differ from default (1.0) processing: for example, + * XML declaration will be automatically added (regardless of setting + * WRITE_XML_DECLARATION) as this is required for reader to + * know to use 1.1 compliant handling. XML 1.1 can be used to allow quoted + * control characters (Ascii codes 0 through 31) as well as additional linefeeds + * and name characters. + */ + WRITE_XML_1_1(false), + + /** + * Feature that controls whether serialization of Java {@code null} values adds + * XML attribute of `xsi:nil`, as defined by XML Schema (see + * this article + * for details) or not. + * If enabled, `xsi:nil` attribute will be added to the empty element; if disabled, + * it will not. + *

+ * Feature is disabled by default for backwards compatibility. + * + * @since 2.10 + */ + WRITE_NULLS_AS_XSI_NIL(false), + + /** + * Feature that determines writing of root values of type {@code ObjectNode} + * ({@code JsonNode} subtype that represents Object content values), + * regarding XML output. + * If enabled and {@code ObjectNode} has exactly one entry (key/value pair), + * then key of that entry is used as the root element name (and value + * is written as contents. Otherwise (if feature disabled, or if root + * {@code ObjectNode} has any other number of key/value entries, + * root element name is determined using normal logic (either explicitly + * configured, or {@code ObjectNode} otherwise). + *

+ * Default setting is {@code disabled} in Jackson 2.x, for backwards compatibility: + * likely to be changed in 3.0 to {@code enabled}. + * + * @since 2.13 + */ + UNWRAP_ROOT_OBJECT_NODE(false), + + /** + * Feature that enables automatic conversion of logical property + * name {@code "xsi:type"} into matching XML name where "type" + * is the local name and "xsi" prefix is bound to URI + * {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}, + * and output is indicated to be done as XML Attribute. + * This is mostly desirable for Polymorphic handling where it is difficult + * to specify XML Namespace for type identifier + * + * @since 2.17 + */ + AUTO_DETECT_XSI_TYPE(false), + + /** + * Feature that determines how floating-point infinity values are + * serialized. + *

+ * By default, {@link Float#POSITIVE_INFINITY} and + * {@link Double#POSITIVE_INFINITY} are serialized as {@code Infinity}, + * and {@link Float#NEGATIVE_INFINITY} and + * {@link Double#NEGATIVE_INFINITY} are serialized as + * {@code -Infinity}. This is the representation that Java normally + * uses for these values (see {@link Float#toString(float)} and + * {@link Double#toString(double)}), but JAXB and other XML + * Schema-conforming readers won't understand it. + *

+ * With this feature enabled, these values are instead serialized as + * {@code INF} and {@code -INF}, respectively. This is the + * representation that XML Schema and JAXB use (see the XML Schema + * primitive types + * float + * and + * double). + *

+ * When deserializing, Jackson always understands both representations, + * so there is no corresponding + * {@link tools.jackson.dataformat.xml.XmlReadFeature}. + *

+ * Feature is disabled by default for backwards compatibility. + */ + WRITE_XML_SCHEMA_CONFORMING_FLOATS(false), + ; + + private final boolean _defaultState; + private final int _mask; + + /** + * Method that calculates bit set (flags) of all features that + * are enabled by default. + */ + public static int collectDefaults() + { + int flags = 0; + for (XmlWriteFeature f : values()) { + if (f.enabledByDefault()) { + flags |= f.getMask(); + } + } + return flags; + } + + private XmlWriteFeature(boolean defaultState) { + _defaultState = defaultState; + _mask = (1 << ordinal()); + } + + @Override public boolean enabledByDefault() { return _defaultState; } + @Override public int getMask() { return _mask; } + @Override public boolean enabledIn(int flags) { return (flags & getMask()) != 0; } +} diff --git a/src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java b/src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java index d3acee0b6..d183e1f1f 100644 --- a/src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java +++ b/src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java @@ -6,7 +6,6 @@ import java.math.BigInteger; import java.util.Set; -import javax.xml.XMLConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; @@ -25,6 +24,7 @@ import tools.jackson.dataformat.xml.PackageVersion; import tools.jackson.dataformat.xml.XmlNameProcessor; +import tools.jackson.dataformat.xml.XmlReadFeature; /** * {@link JsonParser} implementation that exposes XML structure as @@ -51,100 +51,6 @@ public class FromXmlParser .with(StreamReadCapability.UNTYPED_SCALARS) ; - /** - * Enumeration that defines all togglable features for XML parsers. - */ - public enum Feature implements FormatFeature - { - /** - * Feature that enables automatic conversion of incoming "xsi:type" - * (where "type" is the local name and "xsi" prefix is bound to URI - * {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}), - * into Jackson simple Property Name of {@code "xsi:type"}. - * This is usually needed to read content written using - * matching {@code ToXmlGenerator.Feature#AUTO_DETECT_XSI_TYPE} feature, - * usually used for Polymorphic handling where it is difficult - * to specify proper XML Namespace for type identifier. - * - * @since 2.17 - */ - AUTO_DETECT_XSI_TYPE(false), - - /** - * Feature that indicates whether empty XML elements - * (both empty tags like {@code } and {@code } - * (with no intervening cdata) - * are exposed as {@link JsonToken#VALUE_NULL}) or not. - * If they are not - * returned as `null` tokens, they will be returned as {@link JsonToken#VALUE_STRING} - * tokens with textual value of "" (empty String). - *

- * NOTE: in Jackson 2.x, only "true" empty tags were affected, not split ones. With 3.x - * both cases handled uniformly. - *

- * Default setting is {@code false}. - */ - EMPTY_ELEMENT_AS_NULL(false), - - /** - * Feature that indicates whether XML Schema Instance attribute - * {@code xsi:nil} will be processed automatically -- to indicate {@code null} - * values -- or not. - * If enabled, {@code xsi:nil} attribute on any XML element will mark such - * elements as "null values" and any other attributes or child elements they - * might have to be ignored. If disabled this attribute will be exposed like - * any other attribute. - *

- * Default setting is {@code true} since processing was enabled in 2.12. - * - * @since 2.13 - */ - PROCESS_XSI_NIL(true), - - // 16-Nov-2020, tatu: would have been nice to add in 2.12 but is not - // trivial to implement... so leaving out for now - - /* - * Feature that indicates whether reading operation should check that - * the root element's name matches what is expected by read operation: - * if enabled and name does not match, an exception will be thrown; - * if disabled, no checking is done (any element name will do). - *

- * Default setting is {@code true} for backwards compatibility. - * - * @since 2.12 - ENFORCE_VALID_ROOT_NAME(false) - */ - ; - - final boolean _defaultState; - final int _mask; - - /** - * Method that calculates bit set (flags) of all features that - * are enabled by default. - */ - public static int collectDefaults() - { - int flags = 0; - for (Feature f : values()) { - if (f.enabledByDefault()) { - flags |= f.getMask(); - } - } - return flags; - } - - private Feature(boolean defaultState) { - _defaultState = defaultState; - _mask = (1 << ordinal()); - } - - @Override public boolean enabledByDefault() { return _defaultState; } - @Override public int getMask() { return _mask; } - @Override public boolean enabledIn(int flags) { return (flags & getMask()) != 0; } - } - /** * In cases where a start element has both attributes and non-empty textual * value, we have to create a bogus property; we will use this as @@ -165,7 +71,7 @@ private Feature(boolean defaultState) { /** * Bit flag composed of bits that indicate which - * {@link FromXmlParser.Feature}s + * {@link XmlReadFeature}s * are enabled. */ protected int _formatFeatures; diff --git a/src/main/java/tools/jackson/dataformat/xml/deser/XmlTokenStream.java b/src/main/java/tools/jackson/dataformat/xml/deser/XmlTokenStream.java index c1e5e71b1..c30f8b1b9 100644 --- a/src/main/java/tools/jackson/dataformat/xml/deser/XmlTokenStream.java +++ b/src/main/java/tools/jackson/dataformat/xml/deser/XmlTokenStream.java @@ -12,6 +12,7 @@ import tools.jackson.core.io.ContentReference; import tools.jackson.dataformat.xml.XmlNameProcessor; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.util.Stax2JacksonReaderAdapter; /** @@ -68,7 +69,7 @@ public class XmlTokenStream /** * Bit flag composed of bits that indicate which - * {@link FromXmlParser.Feature}s + * {@link XmlReadFeature}s * are enabled. */ protected final int _formatFeatures; @@ -170,8 +171,8 @@ public XmlTokenStream(XMLStreamReader xmlReader, ContentReference sourceRef, { _sourceReference = sourceRef; _formatFeatures = formatFeatures; - _cfgProcessXsiNil = FromXmlParser.Feature.PROCESS_XSI_NIL.enabledIn(_formatFeatures); - _cfgProcessXsiType = FromXmlParser.Feature.AUTO_DETECT_XSI_TYPE.enabledIn(_formatFeatures); + _cfgProcessXsiNil = XmlReadFeature.PROCESS_XSI_NIL.enabledIn(_formatFeatures); + _cfgProcessXsiType = XmlReadFeature.AUTO_DETECT_XSI_TYPE.enabledIn(_formatFeatures); // 04-Dec-2023, tatu: [dataformat-xml#618] Need further customized adapter: _xmlReader = Stax2JacksonReaderAdapter.wrapIfNecessary(xmlReader); _nameProcessor = nameProcessor; @@ -198,7 +199,7 @@ public int initialize() throws XMLStreamException // as of 2.14: otherwise we have lots of issues with empty POJOs, // Lists, Maps if (_xmlReader.isEmptyElement() - && FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures) + && XmlReadFeature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures) && !_xsiNilFound && _attributeCount < 1) { // 06-Sep-2022, tatu: In fact the only special case of null conversion @@ -546,7 +547,7 @@ private final String _collectUntilTag() throws XMLStreamException // 21-Jun-2017, tatu: Whether exposed as `null` or "" is now configurable... if (_xmlReader.isEmptyElement()) { _xmlReader.next(); - if (FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) { + if (XmlReadFeature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) { return null; } return ""; @@ -565,7 +566,7 @@ private final String _collectUntilTag() throws XMLStreamException // as `null`, as long as we default `String` null handling to coerce that to // "empty" if (chars == null) { - if (FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) { + if (XmlReadFeature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) { return null; } return ""; diff --git a/src/main/java/tools/jackson/dataformat/xml/ser/ToXmlGenerator.java b/src/main/java/tools/jackson/dataformat/xml/ser/ToXmlGenerator.java index 7f0ea93aa..3803e0de0 100644 --- a/src/main/java/tools/jackson/dataformat/xml/ser/ToXmlGenerator.java +++ b/src/main/java/tools/jackson/dataformat/xml/ser/ToXmlGenerator.java @@ -20,6 +20,7 @@ import tools.jackson.core.json.DupDetector; import tools.jackson.core.util.SimpleStreamWriteContext; import tools.jackson.dataformat.xml.XmlPrettyPrinter; +import tools.jackson.dataformat.xml.XmlWriteFeature; import tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter; import tools.jackson.dataformat.xml.util.StaxUtil; import tools.jackson.core.util.JacksonFeatureSet; @@ -43,130 +44,7 @@ public class ToXmlGenerator */ protected final static String DEFAULT_UNKNOWN_ELEMENT = "unknown"; - /** - * Enumeration that defines all togglable extra XML-specific features - */ - public enum Feature implements FormatFeature - { - /** - * Feature that controls whether XML declaration should be written before - * when generator is initialized (true) or not (false) - */ - WRITE_XML_DECLARATION(false), - - /** - * Feature that controls whether output should be done as XML 1.1; if so, - * certain aspects may differ from default (1.0) processing: for example, - * XML declaration will be automatically added (regardless of setting - * WRITE_XML_DECLARATION) as this is required for reader to - * know to use 1.1 compliant handling. XML 1.1 can be used to allow quoted - * control characters (Ascii codes 0 through 31) as well as additional linefeeds - * and name characters. - */ - WRITE_XML_1_1(false), - - /** - * Feature that controls whether serialization of Java {@code null} values adds - * XML attribute of `xsi:nil`, as defined by XML Schema (see - * this article - * for details) or not. - * If enabled, `xsi:nil` attribute will be added to the empty element; if disabled, - * it will not. - *

- * Feature is disabled by default for backwards compatibility. - * - * @since 2.10 - */ - WRITE_NULLS_AS_XSI_NIL(false), - - /** - * Feature that determines writing of root values of type {@code ObjectNode} - * ({@code JsonNode} subtype that represents Object content values), - * regarding XML output. - * If enabled and {@code ObjectNode} has exactly one entry (key/value pair), - * then key of that entry is used as the root element name (and value - * is written as contents. Otherwise (if feature disabled, or if root - * {@code ObjectNode} has any other number of key/value entries, - * root element name is determined using normal logic (either explicitly - * configured, or {@code ObjectNode} otherwise). - *

- * Default setting is {@code disabled} in Jackson 2.x, for backwards compatibility: - * likely to be changed in 3.0 to {@code enabled}. - * - * @since 2.13 - */ - UNWRAP_ROOT_OBJECT_NODE(false), - - /** - * Feature that enables automatic conversion of logical property - * name {@code "xsi:type"} into matching XML name where "type" - * is the local name and "xsi" prefix is bound to URI - * {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}, - * and output is indicated to be done as XML Attribute. - * This is mostly desirable for Polymorphic handling where it is difficult - * to specify XML Namespace for type identifier - * - * @since 2.17 - */ - AUTO_DETECT_XSI_TYPE(false), - - /** - * Feature that determines how floating-point infinity values are - * serialized. - *

- * By default, {@link Float#POSITIVE_INFINITY} and - * {@link Double#POSITIVE_INFINITY} are serialized as {@code Infinity}, - * and {@link Float#NEGATIVE_INFINITY} and - * {@link Double#NEGATIVE_INFINITY} are serialized as - * {@code -Infinity}. This is the representation that Java normally - * uses for these values (see {@link Float#toString(float)} and - * {@link Double#toString(double)}), but JAXB and other XML - * Schema-conforming readers won't understand it. - *

- * With this feature enabled, these values are instead serialized as - * {@code INF} and {@code -INF}, respectively. This is the - * representation that XML Schema and JAXB use (see the XML Schema - * primitive types - * float - * and - * double). - *

- * When deserializing, Jackson always understands both representations, - * so there is no corresponding - * {@link tools.jackson.dataformat.xml.deser.FromXmlParser.Feature}. - *

- * Feature is disabled by default for backwards compatibility. - */ - WRITE_XML_SCHEMA_CONFORMING_FLOATS(false), - ; - - final boolean _defaultState; - final int _mask; - - /** - * Method that calculates bit set (flags) of all features that - * are enabled by default. - */ - public static int collectDefaults() - { - int flags = 0; - for (Feature f : values()) { - if (f.enabledByDefault()) { - flags |= f.getMask(); - } - } - return flags; - } - - private Feature(boolean defaultState) { - _defaultState = defaultState; - _mask = (1 << ordinal()); - } - - @Override public boolean enabledByDefault() { return _defaultState; } - @Override public int getMask() { return _mask; } - @Override public boolean enabledIn(int flags) { return (flags & getMask()) != 0; } - } + /* /********************************************************************** @@ -185,7 +63,7 @@ private Feature(boolean defaultState) { /** * Bit flag composed of bits that indicate which - * {@link ToXmlGenerator.Feature}s + * {@link XmlWriteFeature}s * are enabled. */ protected int _formatFeatures; @@ -297,10 +175,10 @@ public void initGenerator() throws JacksonException _initialized = true; try { boolean xmlDeclWritten; - if (Feature.WRITE_XML_1_1.enabledIn(_formatFeatures)) { + if (XmlWriteFeature.WRITE_XML_1_1.enabledIn(_formatFeatures)) { _xmlWriter.writeStartDocument("UTF-8", "1.1"); xmlDeclWritten = true; - } else if (Feature.WRITE_XML_DECLARATION.enabledIn(_formatFeatures)) { + } else if (XmlWriteFeature.WRITE_XML_DECLARATION.enabledIn(_formatFeatures)) { _xmlWriter.writeStartDocument("UTF-8", "1.0"); xmlDeclWritten = true; } else { @@ -313,7 +191,7 @@ public void initGenerator() throws JacksonException _xmlPrettyPrinter.writePrologLinefeed(_xmlWriter); } } - if (Feature.AUTO_DETECT_XSI_TYPE.enabledIn(_formatFeatures)) { + if (XmlWriteFeature.AUTO_DETECT_XSI_TYPE.enabledIn(_formatFeatures)) { _xmlWriter.setPrefix("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); } } catch (XMLStreamException e) { @@ -381,11 +259,11 @@ public int streamWriteOutputBuffered() { /********************************************************************** */ - public final boolean isEnabled(Feature f) { + public final boolean isEnabled(XmlWriteFeature f) { return (_formatFeatures & f.getMask()) != 0; } - public ToXmlGenerator configure(Feature f, boolean state) { + public ToXmlGenerator configure(XmlWriteFeature f, boolean state) { if (state) { _formatFeatures |= f.getMask(); } else { @@ -539,7 +417,7 @@ public JsonGenerator writeName(String name) throws JacksonException String ns; // 30-Jan-2024, tatu: Surprise! - if (Feature.AUTO_DETECT_XSI_TYPE.enabledIn(_formatFeatures) + if (XmlWriteFeature.AUTO_DETECT_XSI_TYPE.enabledIn(_formatFeatures) && "xsi:type".equals(name)) { setNextName(new QName(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type", "xsi")); @@ -1159,7 +1037,7 @@ public JsonGenerator writeNull() throws JacksonException } else if (checkNextIsUnwrapped()) { // as with above, best left unwritten? } else { - final boolean asXsiNil = isEnabled(Feature.WRITE_NULLS_AS_XSI_NIL); + final boolean asXsiNil = isEnabled(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL); if (_xmlPrettyPrinter != null) { // 12-Nov-2020, tatu: Not clean, due to backwards-compat challenges.. // but has to do @@ -1253,7 +1131,7 @@ public JsonGenerator writeNumber(long l) throws JacksonException @Override public JsonGenerator writeNumber(double d) throws JacksonException { - if (Double.isInfinite(d) && isEnabled(Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)) { + if (Double.isInfinite(d) && isEnabled(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)) { return writeNumber(d > 0d ? "INF" : "-INF"); } @@ -1286,7 +1164,7 @@ public JsonGenerator writeNumber(double d) throws JacksonException @Override public JsonGenerator writeNumber(float f) throws JacksonException { - if (Float.isInfinite(f) && isEnabled(Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)) { + if (Float.isInfinite(f) && isEnabled(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)) { return writeNumber(f > 0f ? "INF" : "-INF"); } diff --git a/src/main/java/tools/jackson/dataformat/xml/ser/XmlSerializationContext.java b/src/main/java/tools/jackson/dataformat/xml/ser/XmlSerializationContext.java index 63fd6b0b6..990e5e6c4 100644 --- a/src/main/java/tools/jackson/dataformat/xml/ser/XmlSerializationContext.java +++ b/src/main/java/tools/jackson/dataformat/xml/ser/XmlSerializationContext.java @@ -16,6 +16,7 @@ import tools.jackson.databind.ser.SerializationContextExt; import tools.jackson.databind.ser.SerializerCache; import tools.jackson.databind.util.TokenBuffer; +import tools.jackson.dataformat.xml.XmlWriteFeature; import tools.jackson.dataformat.xml.util.StaxUtil; import tools.jackson.dataformat.xml.util.TypeUtil; import tools.jackson.dataformat.xml.util.XmlRootNameLookup; @@ -262,7 +263,7 @@ protected QName _rootNameFromConfig() protected boolean _shouldUnwrapObjectNode(ToXmlGenerator xgen, Object value) { - return xgen.isEnabled(ToXmlGenerator.Feature.UNWRAP_ROOT_OBJECT_NODE) + return xgen.isEnabled(XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE) && (value instanceof ObjectNode) && (((ObjectNode) value).size() == 1); } diff --git a/src/test/java/tools/jackson/dataformat/xml/FeatureDefaultsTest.java b/src/test/java/tools/jackson/dataformat/xml/FeatureDefaultsTest.java index f259ad063..9e3acfd86 100644 --- a/src/test/java/tools/jackson/dataformat/xml/FeatureDefaultsTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/FeatureDefaultsTest.java @@ -3,9 +3,6 @@ import tools.jackson.databind.ObjectReader; import tools.jackson.databind.ObjectWriter; -import tools.jackson.dataformat.xml.deser.FromXmlParser; -import tools.jackson.dataformat.xml.ser.ToXmlGenerator; - public class FeatureDefaultsTest extends XmlTestBase { private final XmlMapper MAPPER = newMapper(); @@ -13,12 +10,12 @@ public class FeatureDefaultsTest extends XmlTestBase public void testDeserDefaults() throws Exception { ObjectReader r = MAPPER.reader(); - assertNotSame(r, r.with(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL)); + assertNotSame(r, r.with(XmlReadFeature.EMPTY_ELEMENT_AS_NULL)); } public void testSerDefaults() throws Exception { ObjectWriter w = MAPPER.writer(); - assertNotSame(w, w.with(ToXmlGenerator.Feature.WRITE_XML_1_1)); + assertNotSame(w, w.with(XmlWriteFeature.WRITE_XML_1_1)); } } diff --git a/src/test/java/tools/jackson/dataformat/xml/MapperCopyTest.java b/src/test/java/tools/jackson/dataformat/xml/MapperCopyTest.java index 7f524dfb3..36a1bd275 100644 --- a/src/test/java/tools/jackson/dataformat/xml/MapperCopyTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/MapperCopyTest.java @@ -6,8 +6,6 @@ import tools.jackson.databind.*; -import tools.jackson.dataformat.xml.ser.ToXmlGenerator; - public class MapperCopyTest extends XmlTestBase { @JsonRootName("AnnotatedName") @@ -20,7 +18,7 @@ public void testMapperCopy() { XmlMapper mapper1 = mapperBuilder() .nameForTextElement("foo") - .enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) + .enable(XmlWriteFeature.WRITE_XML_DECLARATION) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) .build(); diff --git a/src/test/java/tools/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java b/src/test/java/tools/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java index 62d0f37c7..2c75b005f 100644 --- a/src/test/java/tools/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java +++ b/src/test/java/tools/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java @@ -2,6 +2,7 @@ import tools.jackson.databind.ObjectReader; import tools.jackson.dataformat.xml.XmlMapper; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty; import tools.jackson.dataformat.xml.annotation.JacksonXmlText; @@ -138,7 +139,7 @@ public void testEmptyRootElem579() throws Exception // // ... EXCEPT that in 3.0 it works just fine - R = R.with(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL); + R = R.with(XmlReadFeature.EMPTY_ELEMENT_AS_NULL); /* R = mapperBuilder().enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) diff --git a/src/test/java/tools/jackson/dataformat/xml/deser/EmptyStringValueTest.java b/src/test/java/tools/jackson/dataformat/xml/deser/EmptyStringValueTest.java index 5a67651ba..9c0eae8d4 100644 --- a/src/test/java/tools/jackson/dataformat/xml/deser/EmptyStringValueTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/deser/EmptyStringValueTest.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.Nulls; import tools.jackson.dataformat.xml.XmlMapper; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty; @@ -80,7 +81,7 @@ public void testEmptyElement() throws Exception // but can be changed XmlMapper mapper2 = mapperBuilder() - .enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) + .enable(XmlReadFeature.EMPTY_ELEMENT_AS_NULL) .withConfigOverride(String.class, o -> o.setNullHandling(JsonSetter.Value.forValueNulls(Nulls.SET))) .build(); diff --git a/src/test/java/tools/jackson/dataformat/xml/deser/NullConversionsSkipTest.java b/src/test/java/tools/jackson/dataformat/xml/deser/NullConversionsSkipTest.java index 25d45c7ca..b975bd165 100644 --- a/src/test/java/tools/jackson/dataformat/xml/deser/NullConversionsSkipTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/deser/NullConversionsSkipTest.java @@ -6,6 +6,7 @@ import tools.jackson.databind.*; import tools.jackson.dataformat.xml.XmlMapper; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; // for [databind#1402]; configurable null handling, specifically with SKIP @@ -47,7 +48,7 @@ public void setValue(String v) { */ private final XmlMapper NULL_EXPOSING_MAPPER = mapperBuilder() - .enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) + .enable(XmlReadFeature.EMPTY_ELEMENT_AS_NULL) .build(); public void testSkipNullField1() throws Exception @@ -102,7 +103,7 @@ public void testSkipNullWithDefaults() throws Exception assertNull(result.value); ObjectMapper mapper = mapperBuilder() - .enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) + .enable(XmlReadFeature.EMPTY_ELEMENT_AS_NULL) .withConfigOverride(String.class, o -> o.setNullHandling(JsonSetter.Value.forValueNulls(Nulls.SKIP))) .build(); diff --git a/src/test/java/tools/jackson/dataformat/xml/deser/XsiNilBasicTest.java b/src/test/java/tools/jackson/dataformat/xml/deser/XsiNilBasicTest.java index eaba003a9..abd9e778e 100644 --- a/src/test/java/tools/jackson/dataformat/xml/deser/XsiNilBasicTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/deser/XsiNilBasicTest.java @@ -4,6 +4,7 @@ import tools.jackson.databind.ObjectReader; import tools.jackson.dataformat.xml.XmlMapper; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; public class XsiNilBasicTest extends XmlTestBase @@ -126,7 +127,7 @@ public void testDisableXsiNilLeafProcessing() throws Exception assertEquals(a2q("{'x':null}"), r.readValue(DOC).toString()); assertEquals(a2q("{'x':{'nil':'true'}}"), - r.without(FromXmlParser.Feature.PROCESS_XSI_NIL) + r.without(XmlReadFeature.PROCESS_XSI_NIL) .readValue(DOC).toString()); } @@ -142,7 +143,7 @@ public void testDisableXsiNilRootProcessing() throws Exception // 07-Jul-2021, tatu: Alas! 2.x sets format feature flags too late to // affect root element. But 3.0 works correctly! yay - ObjectReader noXsiNilReader = r.without(FromXmlParser.Feature.PROCESS_XSI_NIL); + ObjectReader noXsiNilReader = r.without(XmlReadFeature.PROCESS_XSI_NIL); assertEquals(a2q("{'nil':'true'}"), noXsiNilReader.readValue(DOC).toString()); } diff --git a/src/test/java/tools/jackson/dataformat/xml/deser/XsiTypeReadTest.java b/src/test/java/tools/jackson/dataformat/xml/deser/XsiTypeReadTest.java index e51d2c13b..eb7fdb832 100644 --- a/src/test/java/tools/jackson/dataformat/xml/deser/XsiTypeReadTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/deser/XsiTypeReadTest.java @@ -7,8 +7,9 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; import tools.jackson.dataformat.xml.XmlMapper; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; -import tools.jackson.dataformat.xml.ser.ToXmlGenerator; +import tools.jackson.dataformat.xml.XmlWriteFeature; // [dataformat-xml#634] public class XsiTypeReadTest extends XmlTestBase @@ -34,8 +35,8 @@ protected PolyBean() { } } private final XmlMapper XSI_ENABLED_MAPPER = XmlMapper.builder() - .configure(ToXmlGenerator.Feature.AUTO_DETECT_XSI_TYPE, true) - .configure(FromXmlParser.Feature.AUTO_DETECT_XSI_TYPE, true) + .configure(XmlWriteFeature.AUTO_DETECT_XSI_TYPE, true) + .configure(XmlReadFeature.AUTO_DETECT_XSI_TYPE, true) .build(); public void testExplicitXsiTypeReadEnabled() throws Exception diff --git a/src/test/java/tools/jackson/dataformat/xml/lists/EmptyListDeserTest.java b/src/test/java/tools/jackson/dataformat/xml/lists/EmptyListDeserTest.java index 06a810f5f..c5b77681e 100644 --- a/src/test/java/tools/jackson/dataformat/xml/lists/EmptyListDeserTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/lists/EmptyListDeserTest.java @@ -8,7 +8,6 @@ import tools.jackson.core.type.TypeReference; import tools.jackson.dataformat.xml.*; import tools.jackson.dataformat.xml.annotation.*; -import tools.jackson.dataformat.xml.deser.FromXmlParser; public class EmptyListDeserTest extends XmlTestBase { @@ -110,7 +109,7 @@ public void testEmptyList319() throws Exception public void testEmptyListAsNull435() throws Exception { XmlMapper mapper = mapperBuilder() - .enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) + .enable(XmlReadFeature.EMPTY_ELEMENT_AS_NULL) .build(); List result = mapper.readValue("", new TypeReference>() { diff --git a/src/test/java/tools/jackson/dataformat/xml/lists/StringListRoundtripTest.java b/src/test/java/tools/jackson/dataformat/xml/lists/StringListRoundtripTest.java index c6c2050bb..d455d24fc 100644 --- a/src/test/java/tools/jackson/dataformat/xml/lists/StringListRoundtripTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/lists/StringListRoundtripTest.java @@ -10,8 +10,8 @@ import tools.jackson.databind.ObjectMapper; import tools.jackson.dataformat.xml.XmlMapper; -import static tools.jackson.dataformat.xml.deser.FromXmlParser.Feature.PROCESS_XSI_NIL; -import static tools.jackson.dataformat.xml.ser.ToXmlGenerator.Feature.WRITE_NULLS_AS_XSI_NIL; +import static tools.jackson.dataformat.xml.XmlReadFeature.PROCESS_XSI_NIL; +import static tools.jackson.dataformat.xml.XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/tools/jackson/dataformat/xml/node/JsonNodeSerUnwrapped441Test.java b/src/test/java/tools/jackson/dataformat/xml/node/JsonNodeSerUnwrapped441Test.java index 7c65de514..705fb7d4d 100644 --- a/src/test/java/tools/jackson/dataformat/xml/node/JsonNodeSerUnwrapped441Test.java +++ b/src/test/java/tools/jackson/dataformat/xml/node/JsonNodeSerUnwrapped441Test.java @@ -7,7 +7,7 @@ import tools.jackson.databind.node.ArrayNode; import tools.jackson.databind.node.ObjectNode; import tools.jackson.dataformat.xml.XmlTestBase; -import tools.jackson.dataformat.xml.ser.ToXmlGenerator; +import tools.jackson.dataformat.xml.XmlWriteFeature; public class JsonNodeSerUnwrapped441Test extends XmlTestBase { @@ -22,9 +22,9 @@ static class Stuff441 { private final ObjectMapper XML_MAPPER = newMapper(); private final ObjectWriter XML_WRITER_WRAP = XML_MAPPER.writer() - .without(ToXmlGenerator.Feature.UNWRAP_ROOT_OBJECT_NODE); + .without(XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE); private final ObjectWriter XML_WRITER_UNWRAP = XML_MAPPER.writer() - .with(ToXmlGenerator.Feature.UNWRAP_ROOT_OBJECT_NODE); + .with(XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE); // [dataformat-xml#441]: before changes, work-around should be fine public void testOlderWorkaround() throws Exception diff --git a/src/test/java/tools/jackson/dataformat/xml/ser/TestSerialization.java b/src/test/java/tools/jackson/dataformat/xml/ser/TestSerialization.java index 2a9d9a05b..f53152f01 100644 --- a/src/test/java/tools/jackson/dataformat/xml/ser/TestSerialization.java +++ b/src/test/java/tools/jackson/dataformat/xml/ser/TestSerialization.java @@ -7,6 +7,7 @@ import tools.jackson.databind.ObjectWriter; import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestBase; +import tools.jackson.dataformat.xml.XmlWriteFeature; import tools.jackson.dataformat.xml.annotation.JacksonXmlCData; import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty; @@ -213,8 +214,8 @@ public void testFloatInfinity() throws Exception private void checkFloatInfinity(Floats original, boolean xmlSchemaConforming, String expectedXml) throws Exception { ObjectWriter w = _xmlMapper.writer(); - w = xmlSchemaConforming ? w.with(ToXmlGenerator.Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS) - : w.without(ToXmlGenerator.Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS); + w = xmlSchemaConforming ? w.with(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS) + : w.without(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS); String xml = w.writeValueAsString(original); xml = removeSjsxpNamespace(xml); @@ -244,8 +245,8 @@ public void testDoubleInfinity() throws Exception private void checkDoubleInfinity(Doubles original, boolean xmlSchemaConforming, String expectedXml) throws Exception { ObjectWriter w = _xmlMapper.writer(); - w = xmlSchemaConforming ? w.with(ToXmlGenerator.Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS) - : w.without(ToXmlGenerator.Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS); + w = xmlSchemaConforming ? w.with(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS) + : w.without(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS); String xml = w.writeValueAsString(original); xml = removeSjsxpNamespace(xml); diff --git a/src/test/java/tools/jackson/dataformat/xml/ser/TestSerializationManual.java b/src/test/java/tools/jackson/dataformat/xml/ser/TestSerializationManual.java index 5811859b6..a25e65a1c 100644 --- a/src/test/java/tools/jackson/dataformat/xml/ser/TestSerializationManual.java +++ b/src/test/java/tools/jackson/dataformat/xml/ser/TestSerializationManual.java @@ -7,6 +7,7 @@ import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestBase; +import tools.jackson.dataformat.xml.XmlWriteFeature; public class TestSerializationManual extends XmlTestBase { @@ -25,7 +26,7 @@ public static class Value { public void testIssue54() throws Exception { XmlMapper xmlMapper = XmlMapper.builder() - .enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) + .enable(XmlWriteFeature.WRITE_XML_DECLARATION) .build(); StringWriter sw = new StringWriter(); ToXmlGenerator generator = (ToXmlGenerator) xmlMapper.createGenerator(sw); diff --git a/src/test/java/tools/jackson/dataformat/xml/ser/TestXmlDeclaration.java b/src/test/java/tools/jackson/dataformat/xml/ser/TestXmlDeclaration.java index a0ccfe4eb..181ba3245 100644 --- a/src/test/java/tools/jackson/dataformat/xml/ser/TestXmlDeclaration.java +++ b/src/test/java/tools/jackson/dataformat/xml/ser/TestXmlDeclaration.java @@ -2,6 +2,7 @@ import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestBase; +import tools.jackson.dataformat.xml.XmlWriteFeature; public class TestXmlDeclaration extends XmlTestBase { @@ -14,7 +15,7 @@ public class TestXmlDeclaration extends XmlTestBase public void testXml10Declaration() throws Exception { XmlMapper mapper = XmlMapper.builder() - .configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true) + .configure(XmlWriteFeature.WRITE_XML_DECLARATION, true) .build(); String xml = mapper.writeValueAsString(new StringBean("123")); assertEquals(xml, "123"); @@ -23,7 +24,7 @@ public void testXml10Declaration() throws Exception public void testXml11Declaration() throws Exception { XmlMapper mapper = XmlMapper.builder() - .enable(ToXmlGenerator.Feature.WRITE_XML_1_1) + .enable(XmlWriteFeature.WRITE_XML_1_1) .build(); String xml = mapper.writeValueAsString(new StringBean("abcd")); assertEquals(xml, "abcd"); diff --git a/src/test/java/tools/jackson/dataformat/xml/ser/XmlPrettyPrinterTest.java b/src/test/java/tools/jackson/dataformat/xml/ser/XmlPrettyPrinterTest.java index 63431149f..aa10ab6ae 100644 --- a/src/test/java/tools/jackson/dataformat/xml/ser/XmlPrettyPrinterTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/ser/XmlPrettyPrinterTest.java @@ -9,6 +9,7 @@ import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestBase; +import tools.jackson.dataformat.xml.XmlWriteFeature; import tools.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty; import tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter; @@ -181,7 +182,7 @@ public void testMultiLevel172() throws Exception Company root = new Company(); root.employee.add(new Employee("abc")); String xml = _xmlMapper.writer() - .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) + .with(XmlWriteFeature.WRITE_XML_DECLARATION) .writeValueAsString(root); // unify possible apostrophes to quotes xml = a2q(xml); @@ -207,7 +208,7 @@ public void testNewLine_withCustomNewLine() throws Exception { String xml = _xmlMapper.writer() .with(customXmlPrettyPrinter) - .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) + .with(XmlWriteFeature.WRITE_XML_DECLARATION) .writeValueAsString(root); // unify possible apostrophes to quotes xml = a2q(xml); @@ -231,7 +232,7 @@ public void testNewLine_systemDefault() throws Exception { String xml = _xmlMapper.writer() .with(new DefaultXmlPrettyPrinter()) - .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) + .with(XmlWriteFeature.WRITE_XML_DECLARATION) .writeValueAsString(root); // unify possible apostrophes to quotes xml = a2q(xml); @@ -255,7 +256,7 @@ public void testNewLine_UseSystemDefaultLineSeperatorOnNullCustomNewLine() throw String xml = _xmlMapper.writer() .with(new DefaultXmlPrettyPrinter().withCustomNewLine(null)) - .with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION) + .with(XmlWriteFeature.WRITE_XML_DECLARATION) .writeValueAsString(root); // unify possible apostrophes to quotes xml = a2q(xml); diff --git a/src/test/java/tools/jackson/dataformat/xml/ser/XsiNilSerializationTest.java b/src/test/java/tools/jackson/dataformat/xml/ser/XsiNilSerializationTest.java index 76bc92146..dec099238 100644 --- a/src/test/java/tools/jackson/dataformat/xml/ser/XsiNilSerializationTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/ser/XsiNilSerializationTest.java @@ -4,6 +4,7 @@ import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestBase; +import tools.jackson.dataformat.xml.XmlWriteFeature; // [dataformat-xml#360] public class XsiNilSerializationTest extends XmlTestBase @@ -17,7 +18,7 @@ public WrapperBean() { } } private final XmlMapper MAPPER = XmlMapper.builder() - .configure(ToXmlGenerator.Feature.WRITE_NULLS_AS_XSI_NIL, true) + .configure(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL, true) .build(); // [dataformat-xml#360] diff --git a/src/test/java/tools/jackson/dataformat/xml/ser/XsiTypeWriteTest.java b/src/test/java/tools/jackson/dataformat/xml/ser/XsiTypeWriteTest.java index 1afb9c005..75a6dd547 100644 --- a/src/test/java/tools/jackson/dataformat/xml/ser/XsiTypeWriteTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/ser/XsiTypeWriteTest.java @@ -8,6 +8,7 @@ import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestBase; +import tools.jackson.dataformat.xml.XmlWriteFeature; // [dataformat-xml#324] public class XsiTypeWriteTest extends XmlTestBase @@ -25,11 +26,11 @@ static class PolyBean { } private final XmlMapper NO_XSI_MAPPER = XmlMapper.builder() - .configure(ToXmlGenerator.Feature.AUTO_DETECT_XSI_TYPE, false) + .configure(XmlWriteFeature.AUTO_DETECT_XSI_TYPE, false) .build(); private final XmlMapper XSI_ENABLED_MAPPER = XmlMapper.builder() - .configure(ToXmlGenerator.Feature.AUTO_DETECT_XSI_TYPE, true) + .configure(XmlWriteFeature.AUTO_DETECT_XSI_TYPE, true) .build(); public void testExplicitXsiTypeWriteDisabled() throws Exception diff --git a/src/test/java/tools/jackson/dataformat/xml/stream/XmlParserTest.java b/src/test/java/tools/jackson/dataformat/xml/stream/XmlParserTest.java index 734b5be49..c468f018d 100644 --- a/src/test/java/tools/jackson/dataformat/xml/stream/XmlParserTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/stream/XmlParserTest.java @@ -10,6 +10,7 @@ import tools.jackson.databind.ObjectReader; import tools.jackson.databind.json.JsonMapper; import tools.jackson.dataformat.xml.XmlMapper; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; import tools.jackson.dataformat.xml.deser.FromXmlParser; @@ -53,7 +54,7 @@ public void testSimpleWithEmpty() throws Exception final String XML = ""; // -> "{"leaf":null}" - try (JsonParser p = _xmlMapper.reader().with(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) + try (JsonParser p = _xmlMapper.reader().with(XmlReadFeature.EMPTY_ELEMENT_AS_NULL) .createParser(XML)) { assertToken(JsonToken.START_OBJECT, p.nextToken()); assertToken(JsonToken.PROPERTY_NAME, p.nextToken()); @@ -64,7 +65,7 @@ public void testSimpleWithEmpty() throws Exception } // -> "{"leaf":""}" - try (JsonParser p = _xmlMapper.reader().without(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) + try (JsonParser p = _xmlMapper.reader().without(XmlReadFeature.EMPTY_ELEMENT_AS_NULL) .createParser(XML)) { assertToken(JsonToken.START_OBJECT, p.nextToken()); assertToken(JsonToken.PROPERTY_NAME, p.nextToken()); diff --git a/src/test/java/tools/jackson/dataformat/xml/stream/XmlTokenStreamTest.java b/src/test/java/tools/jackson/dataformat/xml/stream/XmlTokenStreamTest.java index 252563bbe..c3b08ac22 100644 --- a/src/test/java/tools/jackson/dataformat/xml/stream/XmlTokenStreamTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/stream/XmlTokenStreamTest.java @@ -7,8 +7,8 @@ import tools.jackson.core.io.ContentReference; import tools.jackson.dataformat.xml.XmlFactory; import tools.jackson.dataformat.xml.XmlNameProcessors; +import tools.jackson.dataformat.xml.XmlReadFeature; import tools.jackson.dataformat.xml.XmlTestBase; -import tools.jackson.dataformat.xml.deser.FromXmlParser; import tools.jackson.dataformat.xml.deser.XmlTokenStream; // NOTE: test changed a lot between 2.13 and 2.14: @@ -46,11 +46,11 @@ public void testRootAttributes() throws Exception public void _testRootAttributes(boolean emptyAsNull) throws Exception { String XML = ""; - int f = FromXmlParser.Feature.collectDefaults(); + int f = XmlReadFeature.collectDefaults(); if (emptyAsNull) { - f |= FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.getMask(); + f |= XmlReadFeature.EMPTY_ELEMENT_AS_NULL.getMask(); } else { - f &= ~FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.getMask(); + f &= ~XmlReadFeature.EMPTY_ELEMENT_AS_NULL.getMask(); } XmlTokenStream tokens = _tokensFor(XML, f); assertEquals(XmlTokenStream.XML_START_ELEMENT, tokens.getCurrentToken()); @@ -76,11 +76,11 @@ public void testEmptyTags() throws Exception private void _testEmptyTags(boolean emptyAsNull) throws Exception { String XML = ""; - int f = FromXmlParser.Feature.collectDefaults(); + int f = XmlReadFeature.collectDefaults(); if (emptyAsNull) { - f |= FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.getMask(); + f |= XmlReadFeature.EMPTY_ELEMENT_AS_NULL.getMask(); } else { - f &= ~FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.getMask(); + f &= ~XmlReadFeature.EMPTY_ELEMENT_AS_NULL.getMask(); } XmlTokenStream tokens = _tokensFor(XML, f); assertEquals(XmlTokenStream.XML_START_ELEMENT, tokens.getCurrentToken()); @@ -171,7 +171,7 @@ public void testMixedContentAfter() throws Exception } private XmlTokenStream _tokensFor(String doc) throws Exception { - return _tokensFor(doc, FromXmlParser.Feature.collectDefaults()); + return _tokensFor(doc, XmlReadFeature.collectDefaults()); } private XmlTokenStream _tokensFor(String doc, int flags) throws Exception