diff --git a/release-notes/VERSION b/release-notes/VERSION index 6060acbb1..cbd31291c 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -14,5 +14,8 @@ Version: 3.x (for earlier see VERSION-2.x) `ToXmlGenerator.Feature` as `XmlWriteFeature` #701: Change 3.0 to use `module-info.java` directly, remove use of Moditect #725: Change `XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE` default to `true` +#727: Change `XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL` default to `true` +#728: Change `XmlWriteFeature.AUTO_DETECT_XSI_TYPE` default to `true` +#729: Change `XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS` default to `true` - Add `XmlMapper.shared()` - Minimum Java baseline: Java 17 diff --git a/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java b/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java index 99431b4ee..8e42e2cc4 100644 --- a/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java +++ b/src/main/java/tools/jackson/dataformat/xml/XmlWriteFeature.java @@ -36,9 +36,10 @@ public enum XmlWriteFeature implements FormatFeature * 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. + * Default setting is {@code true} (enabled) in Jackson 3.x: + * it was {@code false} (disabled)in Jackson 2.x. */ - WRITE_NULLS_AS_XSI_NIL(false), + WRITE_NULLS_AS_XSI_NIL(true), /** * Feature that determines writing of root values of type {@code ObjectNode} @@ -51,8 +52,8 @@ public enum XmlWriteFeature implements FormatFeature * root element name is determined using normal logic (either explicitly * configured, or {@code ObjectNode} otherwise). *

- * Default setting is {@code true} (enabled) in Jackson 3.0: - * it was {@code false} in Jackson 2.x. + * Default setting is {@code true} (enabled) in Jackson 3.x: + * it was {@code false} (disabled)in Jackson 2.x. */ UNWRAP_ROOT_OBJECT_NODE(true), @@ -64,8 +65,11 @@ public enum XmlWriteFeature implements FormatFeature * 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 + *

+ * Default setting is {@code true} (enabled) in Jackson 3.0: + * it was {@code false} (disabled)in Jackson 2.x. */ - AUTO_DETECT_XSI_TYPE(false), + AUTO_DETECT_XSI_TYPE(true), /** * Feature that determines how floating-point infinity values are @@ -92,9 +96,10 @@ public enum XmlWriteFeature implements FormatFeature * so there is no corresponding * {@link tools.jackson.dataformat.xml.XmlReadFeature}. *

- * Feature is disabled by default for backwards compatibility. + * Default setting is {@code true} (enabled) in Jackson 3.0: + * it was {@code false} (disabled)in Jackson 2.x. */ - WRITE_XML_SCHEMA_CONFORMING_FLOATS(false), + WRITE_XML_SCHEMA_CONFORMING_FLOATS(true), ; private final boolean _defaultState; diff --git a/src/main/java/tools/jackson/dataformat/xml/annotation/JacksonXmlRootElement.java b/src/main/java/tools/jackson/dataformat/xml/annotation/JacksonXmlRootElement.java index fd3dbcc46..3d3612de1 100644 --- a/src/main/java/tools/jackson/dataformat/xml/annotation/JacksonXmlRootElement.java +++ b/src/main/java/tools/jackson/dataformat/xml/annotation/JacksonXmlRootElement.java @@ -21,9 +21,12 @@ * {@link com.fasterxml.jackson.annotation.JsonRootName} instead. * About the only expected usage may be to have different root name for XML * content than other formats. + * + * @deprecated Since 2.4 use {@link com.fasterxml.jackson.annotation.JsonRootName} instead */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) +@Deprecated public @interface JacksonXmlRootElement { String namespace() default ""; diff --git a/src/test/java/tools/jackson/dataformat/xml/misc/RootNameTest.java b/src/test/java/tools/jackson/dataformat/xml/misc/RootNameTest.java index 4ede0c222..044257f8e 100644 --- a/src/test/java/tools/jackson/dataformat/xml/misc/RootNameTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/misc/RootNameTest.java @@ -1,6 +1,5 @@ package tools.jackson.dataformat.xml.misc; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -10,6 +9,7 @@ import tools.jackson.databind.PropertyName; import tools.jackson.dataformat.xml.XmlTestUtil; +import tools.jackson.dataformat.xml.XmlWriteFeature; import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @@ -17,8 +17,9 @@ import static org.junit.jupiter.api.Assertions.fail; // NOTE: even tho `@JacksonXmlRootElement` will be deprecated in near -// future (possibly in 2.13) -- to be replaced by `@JsonRootName` -- this +// future -- to be replaced by `@JsonRootName` -- this // test will use it to ensure we handle both annotations as expected +@SuppressWarnings({ "serial" }) public class RootNameTest extends XmlTestUtil { static class RootBeanBase @@ -31,19 +32,21 @@ public RootBeanBase(String v) { } } + @SuppressWarnings("deprecation") @JacksonXmlRootElement(localName="root") static class RootBean extends RootBeanBase { protected RootBean() { super(); } } + @SuppressWarnings("deprecation") @JacksonXmlRootElement(localName="nsRoot", namespace="http://foo") static class NsRootBean { public String value = "abc"; } - @SuppressWarnings("serial") + @SuppressWarnings("deprecation") @JacksonXmlRootElement(localName="TheStrings") static class StringList extends ArrayList { public StringList(String...strings) { @@ -57,11 +60,13 @@ public StringList(String...strings) { /********************************************************** */ - protected XmlMapper _xmlMapper = new XmlMapper(); + protected XmlMapper _xmlMapper = mapperBuilder() + .disable(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL) + .build(); // Unit test to verify that root name is properly set @Test - public void testRootNameAnnotation() throws IOException + public void testRootNameAnnotation() { String xml = _xmlMapper.writeValueAsString(new StringBean()); @@ -87,7 +92,7 @@ public void testRootNameAnnotation() throws IOException } @Test - public void testDynamicRootName() throws IOException + public void testDynamicRootName() { String xml; @@ -105,7 +110,7 @@ public void testDynamicRootName() throws IOException } @Test - public void testDynamicRootNameForList() throws IOException + public void testDynamicRootNameForList() { String xml; diff --git a/src/test/java/tools/jackson/dataformat/xml/stream/XmlGeneratorTest.java b/src/test/java/tools/jackson/dataformat/xml/stream/XmlGeneratorTest.java index 78a27b1af..feb141526 100644 --- a/src/test/java/tools/jackson/dataformat/xml/stream/XmlGeneratorTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/stream/XmlGeneratorTest.java @@ -8,13 +8,16 @@ import tools.jackson.dataformat.xml.XmlMapper; import tools.jackson.dataformat.xml.XmlTestUtil; +import tools.jackson.dataformat.xml.XmlWriteFeature; import tools.jackson.dataformat.xml.ser.ToXmlGenerator; import static org.junit.jupiter.api.Assertions.assertEquals; public class XmlGeneratorTest extends XmlTestUtil { - private final XmlMapper MAPPER = xmlMapper(true); + private final XmlMapper MAPPER = mapperBuilder(true) + .disable(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL) + .build(); @Test public void testSimpleElement() 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 f3284364f..280cf5531 100644 --- a/src/test/java/tools/jackson/dataformat/xml/stream/XmlParserTest.java +++ b/src/test/java/tools/jackson/dataformat/xml/stream/XmlParserTest.java @@ -17,7 +17,10 @@ public class XmlParserTest extends XmlTestUtil { protected final ObjectMapper _jsonMapper = new JsonMapper(); - protected final XmlMapper _xmlMapper = newMapper(); + protected final XmlMapper _xmlMapper = mapperBuilder() + // Test written for 2.x which does not unwrap nodes so + .disable(XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE) + .build(); /* /**********************************************************************