Skip to content
Commits on Source (9)
......@@ -19,3 +19,4 @@ target
*.iml
*.ipr
*.iws
.idea
language: java
jdk:
- openjdk7
- openjdk8
- oraclejdk9
- openjdk11
branches:
only:
- master
- "2.9"
- "2.10"
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
jackson-dataformat-xml (2.10.0-1) unstable; urgency=medium
* New upstream version 2.10.0.
* Declare compliance with Debian Policy 4.4.1.
-- Markus Koschany <apo@debian.org> Thu, 03 Oct 2019 17:48:55 +0200
jackson-dataformat-xml (2.9.9-1) unstable; urgency=medium
* New upstream version 2.9.9.
......
......@@ -25,7 +25,7 @@ Build-Depends:
libstax2-api-java (>= 3.1.1),
maven-debian-helper (>= 1.5),
xmlstarlet
Standards-Version: 4.4.0
Standards-Version: 4.4.1
Vcs-Git: https://salsa.debian.org/java-team/jackson-dataformat-xml.git
Vcs-Browser: https://salsa.debian.org/java-team/jackson-dataformat-xml
Homepage: https://github.com/FasterXML/jackson-dataformat-xml
......
......@@ -5,7 +5,7 @@ Files-Excluded:
docs/*
Files: *
Copyright: 2015-2017, FasterXML, LLC, Seattle, USA <info@fasterxml.com>
Copyright: 2015-2019, FasterXML, LLC, Seattle, USA <info@fasterxml.com>
License: Apache-2.0
Comment:
See src/main/resources/META-INF/LICENSE and
......
......@@ -2,3 +2,5 @@
javax.xml.stream stax-api * * * *
com.fasterxml.woodstox woodstox-core * * * *
junit junit * * * *
org.moditect moditect-maven-plugin * * * *
jakarta.xml.bind jakarta.xml.bind-api * * * *
......@@ -14,7 +14,7 @@ index b72dfa1..3264169 100644
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
- <version>2.9.9</version>
- <version>2.10.0</version>
+ <version>debian</version>
</parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
......
version=3
opts=dversionmangle=s/(\da?)[\+\.\-~](?:dfsg|debian|ds|repack|repacked)\.?\d*$/$1/,uversionmangle=s/_/./g;s/\.Beta/~beta/;s/\.Final//;s/-rc/~rc/ \
opts=dversionmangle=s/(\da?)[\+\.\-~](?:dfsg|debian|ds|repack|repacked)\.?\d*$/$1/,uversionmangle=s/_/./g;s/\.Beta/~beta/;s/\.pr\d//;s/\.Final//;s/-rc/~rc/ \
https://github.com/FasterXML/jackson-dataformat-xml/tags \
.*/archive/(?:upstream/)?(?:v||version-|release-|X|R|r)jackson-dataformat-xml-(\d\S*)\.tar\.gz
......@@ -4,11 +4,11 @@
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
<version>2.9.9</version>
<version>2.10.0</version>
</parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.9</version>
<version>2.10.0</version>
<name>Jackson-dataformat-XML</name>
<packaging>bundle</packaging>
<description>Data format extension for Jackson (http://jackson.codehaus.org) to offer
......@@ -16,12 +16,12 @@ alternative support for serializing POJOs as XML and deserializing XML as pojos.
Support implemented on top of Stax API (javax.xml.stream), by implementing core Jackson Streaming API types like JsonGenerator, JsonParser and JsonFactory.
Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMapper).
</description>
<url>http://wiki.fasterxml.com/JacksonExtensionXmlDataBinding</url>
<url>https://github.com/FasterXML/jackson-dataformat-xml</url>
<scm>
<connection>scm:git:git@github.com:FasterXML/jackson-dataformat-xml.git</connection>
<developerConnection>scm:git:git@github.com:FasterXML/jackson-dataformat-xml.git</developerConnection>
<url>http://github.com/FasterXML/jackson-dataformat-xml</url>
<tag>jackson-dataformat-xml-2.9.9</tag>
<tag>jackson-dataformat-xml-2.10.0</tag>
</scm>
<properties>
<packageVersion.dir>com/fasterxml/jackson/dataformat/xml</packageVersion.dir>
......@@ -52,25 +52,29 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>
<!-- JDK 1.6 provides stax-api (javax.xml.stream), but let's add this for documentation
<!-- 20-Mar-2019, tatu: Stax-api been part of JDK since Java 6, so let's drop
dependency as it causes issues with JDK9+ module info
-->
<!--
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
<scope>provided</scope>
</dependency>
-->
<!-- But Stax2 API must be included -->
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<!-- 01-Jan-2010, Stupid Maven Release plug-in mandates a non-range
version
-->
<!--
<version>[3.0.4, 3.5.0)</version>
-->
<version>3.1.4</version>
<version>4.2</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- and a Stax impl is needed: SJSXP (from JDK 1.6) might work, but always
has odd issues. Let's default to Woodstox: caller can upgrade to Aalto
......@@ -79,10 +83,17 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
<!-- 09-May-2016, tatu: With Jackson 2.8, let's make this compile-dep to make it
less likely users accidentally try to use Sjsxp from JDK, which leads to probs
-->
<!-- 16-Jul-2016, tatu: For 2.10, need Woodstox 6.0 to get module info -->
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
<version>5.1.0</version>
<version>6.0.1</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 04-Feb-2018, tatu: Finally, Java 9 does not bundle JAXB, not even API;
......@@ -90,9 +101,9 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
API for runtime too, but first for tests
-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
......@@ -103,18 +114,6 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
</dependency>
</dependencies>
<!-- Alas, need to include snapshot reference since otherwise can not find
snapshot of parent... -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
......@@ -143,7 +142,24 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
</includes>
</configuration>
</plugin>
<!-- 20-Mar-2019, tatu: use Moditect for JDK9+ module info inclusion -->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- Alas, need to include snapshot reference since otherwise can not find
snapshot of parent... -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</project>
......@@ -31,3 +31,27 @@ Yury Vasyutinskiy (Falland@github)
* Contributed #232: Implement `writeRawValue` in `ToXmlGenerator`
(2.9.0)
Victor Khovanskiy (khovanskiy@githib)
* Reported #242: Deserialization of class inheritance depends on attributes order
(2.10.0)
Nelson Dionisi (ndionisi@github)
* Reported #333: `OutputDecorator` not called with `XmlMapper`
(2.10.0)
kevindaub@github.com:
* Reported, contributed fix for #336: WRITE_BIGDECIMAL_AS_PLAIN Not Used When Writing Pretty
(2.10.0)
Sam Smith (Oracle Security Researcher)
* Reported #350: Wrap Xerces/Stax (JDK-bundled) exceptions during parser initialization
(2.10.0)
Rohit Narayanan (rohitnarayanan@github)
* Reported #351: XmlBeanSerializer serializes AnyGetters field even with FilterExceptFilter
(2.10.0)
......@@ -4,10 +4,31 @@ Project: jackson-dataformat-xml
= Releases
------------------------------------------------------------------------
2.10.0 (26-Sep-2019)
#242: Deserialization of class inheritance depends on attributes order
(reported by Victor K)
#325: Problem with '$' in polymorphic type id names when "as class",
"wrapper object", inner class
#326: Force namespace-repairing on `XMLOutputFactory` instances
#350: Wrap Xerces/Stax (JDK-bundled) exceptions during parser initialization
(reported by Sam S)
#351: XmlBeanSerializer serializes AnyGetters field even with FilterExceptFilter
(reported by Rohit N)
#354: Support mapping `xsi:nul` marked elements as `null`s (`JsonToken.VALUE_NULL`)
2.9.10 (not yet released)
#336: WRITE_BIGDECIMAL_AS_PLAIN Not Used When Writing Pretty
(fix contributed by Kevin D)
#340: Incompatible woodstox-core and stax2-api dependencies (upgrade to
`woodstox-core` 5.3.0)
2.9.9 (16-May-2019)
#333: `OutputDecorator` not called with `XmlMapper`
(reported by Nelson D)
- Upgrade `woodstox-core` dependency from 5.0.3 to 5.1.0
2.9.8 (15-Dec-2018)
......
package com.fasterxml.jackson.dataformat.xml;
import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import com.fasterxml.jackson.dataformat.xml.util.StaxUtil;
/**
* Sub-class of {@code StdTypeResolverBuilder} specifically used with
* Default Typing.
*<p>
* Composition/sub-classing gets quite tricky here: ideally we would just
* extend {@link XmlTypeResolverBuilder} but unfortunately inheritance hierarchy
* does not allow this.
*
* @since 2.10
*/
public class DefaultingXmlTypeResolverBuilder
extends ObjectMapper.DefaultTypeResolverBuilder
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public DefaultingXmlTypeResolverBuilder(DefaultTyping t, PolymorphicTypeValidator ptv) {
super(t, ptv);
}
/*
/**********************************************************************
/* Methods copied from `XmlTypeResolverBuilder`
/**********************************************************************
*/
@Override
public StdTypeResolverBuilder init(JsonTypeInfo.Id idType, TypeIdResolver idRes)
{
super.init(idType, idRes);
if (_typeProperty != null) {
_typeProperty = StaxUtil.sanitizeXmlTypeName(_typeProperty);
}
return this;
}
@Override
public StdTypeResolverBuilder typeProperty(String typeIdPropName)
{
// ok to have null/empty; will restore to use defaults
if (typeIdPropName == null || typeIdPropName.length() == 0) {
typeIdPropName = _idType.getDefaultPropertyName();
}
_typeProperty = StaxUtil.sanitizeXmlTypeName(typeIdPropName);
return this;
}
@Override
protected TypeIdResolver idResolver(MapperConfig<?> config,
JavaType baseType, PolymorphicTypeValidator subtypeValidator,
Collection<NamedType> subtypes, boolean forSer, boolean forDeser)
{
if (_customIdResolver != null) {
return _customIdResolver;
}
// Only override handlers of class, minimal class; name is good as is
switch (_idType) {
case CLASS:
return new XmlTypeResolverBuilder.XmlClassNameIdResolver(baseType, config.getTypeFactory(),
subTypeValidator(config));
case MINIMAL_CLASS:
return new XmlTypeResolverBuilder.XmlMinimalClassNameIdResolver(baseType, config.getTypeFactory(),
subTypeValidator(config));
default:
}
return super.idResolver(config, baseType, subtypeValidator, subtypes, forSer, forDeser);
}
}
......@@ -54,6 +54,7 @@ public class JacksonXmlModule
addDeserializer(CharSequence.class, deser);
}
@SuppressWarnings("deprecation")
@Override
public void setupModule(SetupContext context)
{
......
......@@ -137,9 +137,34 @@ public class XmlFactory extends JsonFactory
_xmlOutputFactory = src._xmlOutputFactory;
}
/**
* Constructors used by {@link JsonFactoryBuilder} for instantiation.
*
* @since 2.9
*/
protected XmlFactory(XmlFactoryBuilder b)
{
super(b, false);
_xmlParserFeatures = b.formatParserFeaturesMask();
_xmlGeneratorFeatures = b.formatGeneratorFeaturesMask();
_cfgNameForTextElement = b.nameForTextElement();
_xmlInputFactory = b.xmlInputFactory();
_xmlOutputFactory = b.xmlOutputFactory();
_initFactories(_xmlInputFactory, _xmlOutputFactory);
}
public static XmlFactoryBuilder builder() {
return new XmlFactoryBuilder();
}
@Override
public XmlFactoryBuilder rebuild() {
return new XmlFactoryBuilder(this);
}
protected void _initFactories(XMLInputFactory xmlIn, XMLOutputFactory xmlOut)
{
// Better ensure namespaces get built properly, so:
// [dataformat-xml#326]: Better ensure namespaces get built properly, so:
xmlOut.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
// and for parser, force coalescing as well (much simpler to use)
xmlIn.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
......@@ -149,8 +174,6 @@ public class XmlFactory extends JsonFactory
* Note: compared to base implementation by {@link JsonFactory},
* here the copy will actually share underlying XML input and
* output factories, as there is no way to make copies of those.
*
* @since 2.1
*/
@Override
public XmlFactory copy() {
......@@ -191,18 +214,16 @@ public class XmlFactory extends JsonFactory
if (_jdkXmlOutFactory == null) {
throw new IllegalStateException("No XMLOutputFactory class name read during JDK deserialization");
}
final XMLInputFactory inf;
XMLOutputFactory outf;
try {
XMLInputFactory inf = (XMLInputFactory) Class.forName(_jdkXmlInFactory).newInstance();
XMLOutputFactory outf = (XMLOutputFactory) Class.forName(_jdkXmlOutFactory).newInstance();
return new XmlFactory(_objectCodec, _xmlParserFeatures, _xmlGeneratorFeatures,
inf, outf, _cfgNameForTextElement);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
} catch (InstantiationException e) {
throw new IllegalArgumentException(e);
} catch (IllegalAccessException e) {
inf = (XMLInputFactory) Class.forName(_jdkXmlInFactory).getDeclaredConstructor().newInstance();
outf = (XMLOutputFactory) Class.forName(_jdkXmlOutFactory).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
return new XmlFactory(_objectCodec, _xmlParserFeatures, _xmlGeneratorFeatures,
inf, outf, _cfgNameForTextElement);
}
/**
......@@ -289,6 +310,16 @@ public class XmlFactory extends JsonFactory
return (_xmlParserFeatures & f.getMask()) != 0;
}
@Override
public int getFormatParserFeatures() {
return _xmlParserFeatures;
}
@Override
public int getFormatGeneratorFeatures() {
return _xmlGeneratorFeatures;
}
/*
/******************************************************
/* Configuration, XML, generator settings
......@@ -618,8 +649,8 @@ public class XmlFactory extends JsonFactory
XMLStreamWriter sw;
try {
sw = _xmlOutputFactory.createXMLStreamWriter(_decorate(ctxt, out), "UTF-8");
} catch (XMLStreamException e) {
return StaxUtil.throwAsGenerationException(e, null);
} catch (Exception e) {
throw new JsonGenerationException(e.getMessage(), e, null);
}
return _initializeXmlWriter(sw);
}
......@@ -629,8 +660,8 @@ public class XmlFactory extends JsonFactory
XMLStreamWriter sw;
try {
sw = _xmlOutputFactory.createXMLStreamWriter(_decorate(ctxt, w));
} catch (XMLStreamException e) {
return StaxUtil.throwAsGenerationException(e, null);
} catch (Exception e) {
throw new JsonGenerationException(e.getMessage(), e, null);
}
return _initializeXmlWriter(sw);
}
......@@ -641,8 +672,8 @@ public class XmlFactory extends JsonFactory
// (Woodstox doesn't care) -- otherwise it'll add unnecessary odd declaration
try {
sw.setDefaultNamespace("");
} catch (XMLStreamException e) {
return StaxUtil.throwAsGenerationException(e, null);
} catch (Exception e) {
throw new JsonGenerationException(e.getMessage(), e, null);
}
return sw;
}
......@@ -654,8 +685,9 @@ public class XmlFactory extends JsonFactory
while (sr.next() != XMLStreamConstants.START_ELEMENT) {
;
}
} catch (XMLStreamException e) {
return StaxUtil.throwAsParseException(e, null);
// [dataformat-xml#350]: Xerces-backed impl throws non-XMLStreamException so:
} catch (Exception e) {
throw new JsonParseException(null, e.getMessage(), e);
}
return sr;
}
......
package com.fasterxml.jackson.dataformat.xml;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import com.fasterxml.jackson.core.TSFBuilder;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
/**
* {@link com.fasterxml.jackson.core.TSFBuilder}
* implementation for constructing {@link XmlFactory}
* instances.
*
* @since 3.0
*/
public class XmlFactoryBuilder extends TSFBuilder<XmlFactory, XmlFactoryBuilder>
{
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
/**
* Set of {@link FromXmlParser.Feature}s enabled, as bitmask.
*/
protected int _formatParserFeatures;
/**
* Set of {@link ToXmlGenerator.Feature}s enabled, as bitmask.
*/
protected int _formatGeneratorFeatures;
/**
* Stax factory for creating underlying input stream readers;
* `null` for "use default instance with default settings"
*/
protected XMLInputFactory _xmlInputFactory;
/**
* Stax factory for creating underlying output stream writers;
* `null` for "use default instance with default settings"
*/
protected XMLOutputFactory _xmlOutputFactory;
/**
* 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
* the property name.
*<p>
* Name used for pseudo-property used for returning XML Text value (which does
* not have actual element name to use). Defaults to empty String, but
* may be changed for inter-operability reasons: JAXB, for example, uses
* "value" as name.
*/
protected String _nameForTextElement;
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
protected XmlFactoryBuilder() {
_formatParserFeatures = XmlFactory.DEFAULT_XML_PARSER_FEATURE_FLAGS;
_formatGeneratorFeatures = XmlFactory.DEFAULT_XML_GENERATOR_FEATURE_FLAGS;
}
public XmlFactoryBuilder(XmlFactory base) {
super(base);
_formatParserFeatures = base._xmlParserFeatures;
_formatGeneratorFeatures = base._xmlGeneratorFeatures;
_xmlInputFactory = base._xmlInputFactory;
_xmlOutputFactory = base._xmlOutputFactory;
_nameForTextElement = base._cfgNameForTextElement;
}
// // // Accessors
public int formatParserFeaturesMask() { return _formatParserFeatures; }
public int formatGeneratorFeaturesMask() { return _formatGeneratorFeatures; }
public String nameForTextElement() { return _nameForTextElement; }
public XMLInputFactory xmlInputFactory() {
if (_xmlInputFactory == null) {
return defaultInputFactory();
}
return _xmlInputFactory;
}
protected static XMLInputFactory defaultInputFactory() {
XMLInputFactory xmlIn = XMLInputFactory.newInstance();
// as per [dataformat-xml#190], disable external entity expansion by default
xmlIn.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
// and ditto wrt [dataformat-xml#211], SUPPORT_DTD
xmlIn.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
return xmlIn;
}
public XMLOutputFactory xmlOutputFactory() {
if (_xmlOutputFactory == null) {
return defaultOutputFactory();
}
return _xmlOutputFactory;
}
protected static XMLOutputFactory defaultOutputFactory() {
XMLOutputFactory xmlOut = XMLOutputFactory.newInstance();
// [dataformat-xml#326]: Better ensure namespaces get built properly:
xmlOut.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
return xmlOut;
}
// // // Parser features
public XmlFactoryBuilder enable(FromXmlParser.Feature f) {
_formatParserFeatures |= f.getMask();
return _this();
}
public XmlFactoryBuilder enable(FromXmlParser.Feature first, FromXmlParser.Feature... other) {
_formatParserFeatures |= first.getMask();
for (FromXmlParser.Feature f : other) {
_formatParserFeatures |= f.getMask();
}
return _this();
}
public XmlFactoryBuilder disable(FromXmlParser.Feature f) {
_formatParserFeatures &= ~f.getMask();
return _this();
}
public XmlFactoryBuilder disable(FromXmlParser.Feature first, FromXmlParser.Feature... other) {
_formatParserFeatures &= ~first.getMask();
for (FromXmlParser.Feature f : other) {
_formatParserFeatures &= ~f.getMask();
}
return _this();
}
public XmlFactoryBuilder configure(FromXmlParser.Feature f, boolean state) {
return state ? enable(f) : disable(f);
}
// // // Generator features
public XmlFactoryBuilder enable(ToXmlGenerator.Feature f) {
_formatGeneratorFeatures |= f.getMask();
return _this();
}
public XmlFactoryBuilder enable(ToXmlGenerator.Feature first, ToXmlGenerator.Feature... other) {
_formatGeneratorFeatures |= first.getMask();
for (ToXmlGenerator.Feature f : other) {
_formatGeneratorFeatures |= f.getMask();
}
return _this();
}
public XmlFactoryBuilder disable(ToXmlGenerator.Feature f) {
_formatGeneratorFeatures &= ~f.getMask();
return _this();
}
public XmlFactoryBuilder disable(ToXmlGenerator.Feature first, ToXmlGenerator.Feature... other) {
_formatGeneratorFeatures &= ~first.getMask();
for (ToXmlGenerator.Feature f : other) {
_formatGeneratorFeatures &= ~f.getMask();
}
return _this();
}
public XmlFactoryBuilder configure(ToXmlGenerator.Feature f, boolean state) {
return state ? enable(f) : disable(f);
}
// // // Other config
public XmlFactoryBuilder nameForTextElement(String name) {
_nameForTextElement = name;
return _this();
}
public XmlFactoryBuilder inputFactory(XMLInputFactory xmlIn) {
_xmlInputFactory = xmlIn;
return _this();
}
public XmlFactoryBuilder outputFactory(XMLOutputFactory xmlOut)
{
_xmlOutputFactory = xmlOut;
return _this();
}
// // // Actual construction
@Override
public XmlFactory build() {
// 28-Dec-2017, tatu: No special settings beyond base class ones, so:
return new XmlFactory(this);
}
}
......@@ -10,6 +10,9 @@ import javax.xml.stream.XMLStreamWriter;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperBuilder;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider;
......@@ -32,6 +35,76 @@ public class XmlMapper extends ObjectMapper
// as of 2.6
private static final long serialVersionUID = 1L;
/**
* Builder implementation for constructing {@link XmlMapper} instances.
*
* @since 2.10
*/
public static class Builder extends MapperBuilder<XmlMapper, Builder>
{
public Builder(XmlMapper m) {
super(m);
}
public Builder enable(FromXmlParser.Feature... features) {
for (FromXmlParser.Feature f : features) {
_mapper.enable(f);
}
return this;
}
public Builder disable(FromXmlParser.Feature... features) {
for (FromXmlParser.Feature f : features) {
_mapper.disable(f);
}
return this;
}
public Builder configure(FromXmlParser.Feature feature, boolean state)
{
if (state) {
_mapper.enable(feature);
} else {
_mapper.disable(feature);
}
return this;
}
public Builder enable(ToXmlGenerator.Feature... features) {
for (ToXmlGenerator.Feature f : features) {
_mapper.enable(f);
}
return this;
}
public Builder disable(ToXmlGenerator.Feature... features) {
for (ToXmlGenerator.Feature f : features) {
_mapper.disable(f);
}
return this;
}
public Builder configure(ToXmlGenerator.Feature feature, boolean state)
{
if (state) {
_mapper.enable(feature);
} else {
_mapper.disable(feature);
}
return this;
}
public Builder nameForTextElement(String name) {
_mapper.setXMLTextElementName(name);
return this;
}
public Builder defaultUseWrapper(boolean state) {
_mapper.setDefaultUseWrapper(state);
return this;
}
}
protected final static JacksonXmlModule DEFAULT_XML_MODULE = new JacksonXmlModule();
protected final static DefaultXmlPrettyPrinter DEFAULT_XML_PRETTY_PRINTER = new DefaultXmlPrettyPrinter();
......@@ -104,11 +177,44 @@ public class XmlMapper extends ObjectMapper
return new XmlMapper(this);
}
/**
* @since 2.10
*/
public static XmlMapper.Builder xmlBuilder() {
return new XmlMapper.Builder(new XmlMapper());
}
/**
* @since 2.10
*/
public static XmlMapper.Builder builder() {
return new XmlMapper.Builder(new XmlMapper());
}
/**
* @since 2.10
*/
public static XmlMapper.Builder builder(XmlFactory streamFactory) {
return new XmlMapper.Builder(new XmlMapper(streamFactory));
}
@Override
public Version version() {
return PackageVersion.VERSION;
}
/*
/**********************************************************
/* Factory method overrides
/**********************************************************
*/
@Override // since 2.10
protected TypeResolverBuilder<?> _constructDefaultTypeResolverBuilder(DefaultTyping applicability,
PolymorphicTypeValidator ptv) {
return new DefaultingXmlTypeResolverBuilder(applicability, ptv);
}
/*
/**********************************************************
/* Additional XML-specific configurations
......@@ -122,14 +228,20 @@ public class XmlMapper extends ObjectMapper
* via {@link JacksonXmlModule}.
*
* @since 2.1
*
* @deprecated Since 2.10 use {@link Builder#nameForTextElement(String)} instead
*/
@Deprecated
protected void setXMLTextElementName(String name) {
((XmlFactory) _jsonFactory).setXMLTextElementName(name);
}
/**
* Since 2.7
*
* @deprecated Since 2.10 use {@link Builder#defaultUseWrapper(boolean)} instead
*/
@Deprecated
public XmlMapper setDefaultUseWrapper(boolean state) {
// ser and deser configs should usually have the same introspector, so:
AnnotationIntrospector ai0 = getDeserializationConfig().getAnnotationIntrospector();
......@@ -238,18 +350,4 @@ public class XmlMapper extends ObjectMapper
// NOTE: above call should do flush(); and we should NOT close here.
// Finally, 'g' has no buffers to release.
}
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
// 09-May-2016, tatu: Was removed from `jackson-databind` in 2.8; remove from
// here in 2.9.
@Deprecated // since 2.6
// @Override
protected PrettyPrinter _defaultPrettyPrinter() {
return new DefaultXmlPrettyPrinter();
}
}
......@@ -4,14 +4,17 @@ import java.io.IOException;
import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.ClassNameIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.MinimalClassNameIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.xml.util.StaxUtil;
/**
......@@ -24,6 +27,7 @@ public class XmlTypeResolverBuilder extends StdTypeResolverBuilder
@Override
public StdTypeResolverBuilder init(JsonTypeInfo.Id idType, TypeIdResolver idRes)
{
super.init(idType, idRes);
if (_typeProperty != null) {
_typeProperty = StaxUtil.sanitizeXmlTypeName(_typeProperty);
......@@ -44,21 +48,23 @@ public class XmlTypeResolverBuilder extends StdTypeResolverBuilder
@Override
protected TypeIdResolver idResolver(MapperConfig<?> config,
JavaType baseType, Collection<NamedType> subtypes,
boolean forSer, boolean forDeser)
JavaType baseType, PolymorphicTypeValidator subtypeValidator,
Collection<NamedType> subtypes, boolean forSer, boolean forDeser)
{
if (_customIdResolver != null) {
return _customIdResolver;
}
// Only override handlings of class, minimal class; name is good as is
// Only override handlers of class, minimal class; name is good as is
switch (_idType) {
case CLASS:
return new XmlClassNameIdResolver(baseType, config.getTypeFactory());
return new XmlClassNameIdResolver(baseType, config.getTypeFactory(),
subTypeValidator(config));
case MINIMAL_CLASS:
return new XmlMinimalClassNameIdResolver(baseType, config.getTypeFactory());
return new XmlMinimalClassNameIdResolver(baseType, config.getTypeFactory(),
subTypeValidator(config));
default:
return super.idResolver(config, baseType, subtypes, forSer, forDeser);
}
return super.idResolver(config, baseType, subtypeValidator, subtypes, forSer, forDeser);
}
/*
......@@ -116,9 +122,10 @@ public class XmlTypeResolverBuilder extends StdTypeResolverBuilder
protected static class XmlClassNameIdResolver
extends ClassNameIdResolver
{
public XmlClassNameIdResolver(JavaType baseType, TypeFactory typeFactory)
public XmlClassNameIdResolver(JavaType baseType, TypeFactory typeFactory,
PolymorphicTypeValidator ptv)
{
super(baseType, typeFactory);
super(baseType, typeFactory, ptv);
}
@Override
......@@ -136,9 +143,10 @@ public class XmlTypeResolverBuilder extends StdTypeResolverBuilder
protected static class XmlMinimalClassNameIdResolver
extends MinimalClassNameIdResolver
{
public XmlMinimalClassNameIdResolver(JavaType baseType, TypeFactory typeFactory)
public XmlMinimalClassNameIdResolver(JavaType baseType, TypeFactory typeFactory,
PolymorphicTypeValidator ptv)
{
super(baseType, typeFactory);
super(baseType, typeFactory, ptv);
}
@Override
......
......@@ -176,16 +176,25 @@ public class FromXmlParser
public FromXmlParser(IOContext ctxt, int genericParserFeatures, int xmlFeatures,
ObjectCodec codec, XMLStreamReader xmlReader)
throws IOException
{
super(genericParserFeatures);
_formatFeatures = xmlFeatures;
_ioContext = ctxt;
_objectCodec = codec;
_parsingContext = XmlReadContext.createRootContext(-1, -1);
// and thereby start a scope
_nextToken = JsonToken.START_OBJECT;
_xmlTokens = new XmlTokenStream(xmlReader, ctxt.getSourceReference(),
_formatFeatures);
switch (_xmlTokens.getCurrentToken()) {
case XmlTokenStream.XML_START_ELEMENT:
_nextToken = JsonToken.START_OBJECT;
break;
case XmlTokenStream.XML_NULL:
_nextToken = JsonToken.VALUE_NULL;
break;
default:
_reportError("Internal problem: invalid starting state (%d)", _xmlTokens.getCurrentToken());
}
}
@Override
......@@ -462,11 +471,9 @@ public class FromXmlParser
}
return t;
}
// public JsonToken nextToken0() throws IOException
*/
// public JsonToken nextToken0() throws IOException
@Override
public JsonToken nextToken() throws IOException
{
......@@ -551,8 +558,11 @@ public class FromXmlParser
_parsingContext = _parsingContext.createChildObjectContext(-1, -1);
return (_currToken = JsonToken.START_OBJECT);
}
// 07-Sep-2019, tatu: for [dataformat-xml#353], must NOT return second null
if (_currToken != JsonToken.VALUE_NULL) {
return (_currToken = JsonToken.VALUE_NULL);
}
}
_currToken = _parsingContext.inArray() ? JsonToken.END_ARRAY : JsonToken.END_OBJECT;
_parsingContext = _parsingContext.getParent();
_namesToWrap = _parsingContext.getNamesToWrap();
......@@ -615,6 +625,8 @@ public class FromXmlParser
_parsingContext.setCurrentName(_cfgNameForTextElement);
_nextToken = JsonToken.VALUE_STRING;
return (_currToken = JsonToken.FIELD_NAME);
case XmlTokenStream.XML_NULL:
return (_currToken = JsonToken.VALUE_NULL);
case XmlTokenStream.XML_END:
return (_currToken = null);
}
......@@ -627,6 +639,16 @@ public class FromXmlParser
/**********************************************************
*/
/*
@Override
public String nextFieldName() throws IOException {
if (nextToken() == JsonToken.FIELD_NAME) {
return getCurrentName();
}
return null;
}
*/
/**
* Method overridden to support more reliable deserialization of
* String collections.
......@@ -732,6 +754,9 @@ public class FromXmlParser
_nextToken = JsonToken.VALUE_STRING;
_currToken = JsonToken.FIELD_NAME;
break;
case XmlTokenStream.XML_NULL:
_currToken = JsonToken.VALUE_STRING;
return (_currText = null);
case XmlTokenStream.XML_END:
_currToken = null;
}
......
......@@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.util.JsonParserDelegate;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer;
......@@ -136,11 +137,15 @@ public class WrapperHandlingDeserializer
/**********************************************************************
*/
@SuppressWarnings("resource")
protected final void _configureParser(JsonParser p) throws IOException
{
// 19-Aug-2013, tatu: Although we should not usually get called with
// parser of other types, there are some cases where this may happen:
// specifically, during structural value conversions.
// 05-Sep-2019, tatu: May get XML parser, except for case where content is
// buffered. In that case we may still have access to real parser if we
// are lucky (like in [dataformat-xml#242])
while (p instanceof JsonParserDelegate) {
p = ((JsonParserDelegate) p).delegate();
}
if (p instanceof FromXmlParser) {
((FromXmlParser) p).addVirtualWrapping(_namesToWrap);
}
......