Package list libxstream-java / 29d728b
New upstream version 1.4.14 Markus Koschany 10 months ago
59 changed file(s) with 2281 addition(s) and 1240 deletion(s). Raw diff Collapse all Expand all
11 <mirrors>
22 <mirror>
33 <id>central</id>
4 <url>http://repo1.maven.org/maven2</url>
4 <url>https://repo1.maven.org/maven2</url>
55 <mirrorOf>*</mirrorOf>
66 </mirror>
77 </mirrors>
0 dist: trusty
01 language: java
12 sudo: false
2 addons:
3 apt:
4 packages:
5 - openjdk-6-jdk
63 jdk:
4 - openjdk12
75 - openjdk11
86 - openjdk10
97 - oraclejdk9
10 - oraclejdk8
8 - openjdk8
119 - openjdk7
12 - openjdk6
1310 install: true
1411 script:
15 if [ "$TRAVIS_JDK_VERSION" == "openjdk6" ]; then
16 wget https://archive.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip -P ./target;
17 unzip -qq ./target/apache-maven-3.2.5-bin.zip -d ./target;
18 export M2_HOME=$PWD/target/apache-maven-3.2.5;
19 export PATH=$M2_HOME/bin:$JAVA_HOME/bin:$PATH;
12 if [ "$TRAVIS_JDK_VERSION" == "oraclejdk9" ]; then
2013 export SETTINGS="-s .travis.settings.xml";
2114 fi;
22 if [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ]; then
15 if [ "$TRAVIS_JDK_VERSION" == "openjdk8" ]; then
2316 mkdir -p xstream/profiles/coveralls;
2417 mkdir -p xstream-hibernate/profiles/coveralls;
25 mvn -V -B -e clean package jacoco:report coveralls:report;
18 mvn -V -B -e clean package jacoco:report coveralls:report $SETTINGS;
2619 else
2720 mvn -V -B -e clean package $SETTINGS;
2821 fi
44
55 To build:
66
7 For Java 1.4: rm */profiles/osgi
78 mvn clean install
89
910 Before deploying:
00 (BSD Style License)
11
22 Copyright (c) 2003-2006, Joe Walnes
3 Copyright (c) 2006-2015, XStream Committers
3 Copyright (c) 2006-2019, XStream Committers
44 All rights reserved.
55
66 Redistribution and use in source and binary forms, with or without
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
22 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1313 <groupId>com.thoughtworks.xstream</groupId>
1414 <artifactId>xstream-parent</artifactId>
1515 <packaging>pom</packaging>
16 <version>1.4.11.1</version>
16 <version>1.4.14</version>
1717 <name>XStream Parent</name>
1818 <url>http://x-stream.github.io</url>
1919 <description>
3636
3737 <profiles>
3838 <profile>
39 <id>jdk9-ge</id>
40 <activation>
41 <jdk>[9,</jdk>
39 <id>jdk12-ge</id>
40 <activation>
41 <jdk>[12,)</jdk>
42 </activation>
43 <properties>
44 <version.java.5>1.7</version.java.5>
45 <version.java.6>1.7</version.java.6>
46 <version.java.source>1.7</version.java.source>
47 <version.java.target>1.7</version.java.target>
48 </properties>
49 </profile>
50 <profile>
51 <id>jdk9-ge-jdk12</id>
52 <activation>
53 <jdk>[9,12)</jdk>
4254 </activation>
4355 <properties>
4456 <version.java.5>1.6</version.java.5>
4557 <version.java.source>1.6</version.java.source>
4658 <version.java.target>1.6</version.java.target>
59 </properties>
60 </profile>
61 <profile>
62 <id>jdk9-ge</id>
63 <activation>
64 <jdk>[9,)</jdk>
65 </activation>
66 <properties>
4767 <version.plugin.maven.enforcer>3.0.0-M1</version.plugin.maven.enforcer>
4868 </properties>
4969 </profile>
83103 <jdk>[1.6,)</jdk>
84104 </activation>
85105 <modules>
106 <!--module>xstream-its</module--><!-- requires installed repo -->
86107 <module>xstream-jmh</module>
87108 <module>xstream-distribution</module>
88109 </modules>
124145 </activation>
125146 <build>
126147 <plugins>
148 <plugin>
149 <groupId>org.codehaus.mojo</groupId>
150 <artifactId>build-helper-maven-plugin</artifactId>
151 <executions>
152 <execution>
153 <id>include-license</id>
154 <phase>generate-resources</phase>
155 <goals>
156 <goal>add-resource</goal>
157 </goals>
158 <configuration>
159 <resources>
160 <resource>
161 <directory>${project.build.directory}/generated-resources</directory>
162 </resource>
163 </resources>
164 </configuration>
165 </execution>
166 </executions>
167 </plugin>
168 <plugin>
169 <groupId>org.apache.maven.plugins</groupId>
170 <artifactId>maven-antrun-plugin</artifactId>
171 <executions>
172 <execution>
173 <id>copy-license</id>
174 <phase>generate-resources</phase>
175 <goals>
176 <goal>run</goal>
177 </goals>
178 <configuration>
179 <target>
180 <copy file="../LICENSE.txt" tofile="${project.build.directory}/generated-resources/META-INF/LICENSE" overwrite="false" failonerror="true" />
181 </target>
182 </configuration>
183 </execution>
184 </executions>
185 </plugin>
127186 <plugin>
128187 <groupId>org.apache.maven.plugins</groupId>
129188 <artifactId>maven-source-plugin</artifactId>
145204 <version>${version.java.enforced}</version>
146205 </requireJavaVersion>
147206 </rules>
207 </configuration>
208 </execution>
209 </executions>
210 </plugin>
211 </plugins>
212 </build>
213 </profile>
214 <profile>
215 <id>java-test</id>
216 <activation>
217 <file>
218 <exists>src/test</exists>
219 </file>
220 </activation>
221 <build>
222 <plugins>
223 <plugin>
224 <groupId>org.apache.maven.plugins</groupId>
225 <artifactId>maven-antrun-plugin</artifactId>
226 <executions>
227 <execution>
228 <id>copy-license-for-test</id>
229 <phase>generate-test-resources</phase>
230 <goals>
231 <goal>run</goal>
232 </goals>
233 <configuration>
234 <target>
235 <copy file="../LICENSE.txt" tofile="${project.build.directory}/test-classes/META-INF/LICENSE" overwrite="false" failonerror="true" />
236 </target>
148237 </configuration>
149238 </execution>
150239 </executions>
266355
267356 <licenses>
268357 <license>
269 <name>BSD style</name>
358 <name>BSD-3-Clause</name>
270359 <url>http://x-stream.github.io/license.html</url>
271360 <distribution>repo</distribution>
272361 </license>
320409 <dependency>
321410 <groupId>com.thoughtworks.xstream</groupId>
322411 <artifactId>xstream</artifactId>
323 <version>1.4.11.1</version>
412 <version>1.4.14</version>
324413 </dependency>
325414 <dependency>
326415 <groupId>com.thoughtworks.xstream</groupId>
327416 <artifactId>xstream</artifactId>
328 <version>1.4.11.1</version>
417 <version>1.4.14</version>
329418 <classifier>tests</classifier>
330419 <type>test-jar</type>
331420 <scope>test</scope>
333422 <dependency>
334423 <groupId>com.thoughtworks.xstream</groupId>
335424 <artifactId>xstream</artifactId>
336 <version>1.4.11.1</version>
425 <version>1.4.14</version>
337426 <classifier>javadoc</classifier>
338427 <scope>provided</scope>
339428 </dependency>
340429 <dependency>
341430 <groupId>com.thoughtworks.xstream</groupId>
342431 <artifactId>xstream-hibernate</artifactId>
343 <version>1.4.11.1</version>
432 <version>1.4.14</version>
344433 </dependency>
345434 <dependency>
346435 <groupId>com.thoughtworks.xstream</groupId>
347436 <artifactId>xstream-hibernate</artifactId>
348 <version>1.4.11.1</version>
437 <version>1.4.14</version>
349438 <classifier>javadoc</classifier>
350439 <scope>provided</scope>
351440 </dependency>
352441 <dependency>
353442 <groupId>com.thoughtworks.xstream</groupId>
354443 <artifactId>xstream-jmh</artifactId>
355 <version>1.4.11.1</version>
444 <version>1.4.14</version>
356445 </dependency>
357446 <dependency>
358447 <groupId>com.thoughtworks.xstream</groupId>
359448 <artifactId>xstream-jmh</artifactId>
360 <version>1.4.11.1</version>
449 <version>1.4.14</version>
361450 <classifier>javadoc</classifier>
362451 <scope>provided</scope>
363452 </dependency>
364453 <dependency>
365454 <groupId>com.thoughtworks.xstream</groupId>
366455 <artifactId>xstream-benchmark</artifactId>
367 <version>1.4.11.1</version>
456 <version>1.4.14</version>
368457 </dependency>
369458 <dependency>
370459 <groupId>com.thoughtworks.xstream</groupId>
371460 <artifactId>xstream-benchmark</artifactId>
372 <version>1.4.11.1</version>
461 <version>1.4.14</version>
373462 <classifier>javadoc</classifier>
374463 <scope>provided</scope>
375464 </dependency>
507596 </dependency>
508597
509598 <dependency>
510 <groupId>oro</groupId>
511 <artifactId>oro</artifactId>
512 <version>${version.oro}</version>
513 </dependency>
514
515 <dependency>
516599 <groupId>org.json</groupId>
517600 <artifactId>json</artifactId>
518601 <version>${version.org.json}</version>
622705 <scope>test</scope>
623706 </dependency>
624707
708 <!-- Pax Exam Dependencies -->
709 <dependency>
710 <groupId>org.apache.felix</groupId>
711 <artifactId>org.apache.felix.framework</artifactId>
712 <version>${version.org.apache.felix}</version>
713 <scope>test</scope>
714 </dependency>
715 <dependency>
716 <groupId>org.glassfish.hk2.external</groupId>
717 <artifactId>javax.inject</artifactId>
718 <version>${version.javax.inject}</version>
719 <scope>provided</scope>
720 </dependency>
721 <dependency>
722 <groupId>org.ops4j.pax.exam</groupId>
723 <artifactId>pax-exam-container-native</artifactId>
724 <version>${version.org.ops4j.pax.exam}</version>
725 <scope>test</scope>
726 </dependency>
727 <dependency>
728 <groupId>org.ops4j.pax.exam</groupId>
729 <artifactId>pax-exam-extender-service</artifactId>
730 <version>${version.org.ops4j.pax.exam}</version>
731 <scope>test</scope>
732 </dependency>
733 <dependency>
734 <groupId>org.ops4j.pax.exam</groupId>
735 <artifactId>pax-exam-inject</artifactId>
736 <version>${version.org.ops4j.pax.exam}</version>
737 <scope>test</scope>
738 </dependency>
739 <dependency>
740 <groupId>org.ops4j.pax.exam</groupId>
741 <artifactId>pax-exam-invoker-junit</artifactId>
742 <version>${version.org.ops4j.pax.exam}</version>
743 <scope>test</scope>
744 </dependency>
745 <dependency>
746 <groupId>org.ops4j.pax.exam</groupId>
747 <artifactId>pax-exam-junit4</artifactId>
748 <version>${version.org.ops4j.pax.exam}</version>
749 <scope>test</scope>
750 </dependency>
751 <dependency>
752 <groupId>org.ops4j.pax.exam</groupId>
753 <artifactId>pax-exam-link-assembly</artifactId>
754 <version>${version.org.ops4j.pax.exam}</version>
755 <scope>test</scope>
756 </dependency>
757 <dependency>
758 <groupId>org.ops4j.pax.exam</groupId>
759 <artifactId>pax-exam-link-mvn</artifactId><!-- Preferred link because it does not require an mvn url handler implicitely. -->
760 <version>${version.org.ops4j.pax.exam}</version>
761 <scope>test</scope>
762 </dependency>
625763 </dependencies>
626764 </dependencyManagement>
627765
698836 </plugin>
699837 <plugin>
700838 <groupId>org.apache.maven.plugins</groupId>
839 <artifactId>maven-failsafe-plugin</artifactId>
840 <version>${version.plugin.maven.failsafe}</version>
841 </plugin>
842 <plugin>
843 <groupId>org.apache.maven.plugins</groupId>
701844 <artifactId>maven-gpg-plugin</artifactId>
702845 <version>${version.plugin.maven.gpg}</version>
703846 </plugin>
718861 </manifest>
719862 <manifestEntries>
720863 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
864 <Bundle-License>BSD-3-Clause</Bundle-License>
721865 <X-Compile-Source>${version.java.source}</X-Compile-Source>
722866 <X-Compile-Target>${version.java.target}</X-Compile-Target>
723867 <X-Builder>Maven ${maven.version}</X-Builder>
753897 </manifest>
754898 <manifestEntries>
755899 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
900 <Bundle-License>BSD-3-Clause</Bundle-License>
756901 </manifestEntries>
757902 </archive>
758903 </configuration>
810955 <Bundle-SymbolicName>${project.artifactId}.sources</Bundle-SymbolicName>
811956 <Bundle-Vendor>${project.organization.name} Sources</Bundle-Vendor>
812957 <Bundle-Version>${project.info.osgiVersion} Sources</Bundle-Version>
958 <Bundle-License>BSD-3-Clause</Bundle-License>
813959 <Eclipse-SourceBundle>${project.artifactId};version=${project.info.osgiVersion}</Eclipse-SourceBundle>
814960 <X-Compile-Source>${version.java.source}</X-Compile-Source>
815961 <X-Compile-Target>${version.java.target}</X-Compile-Target>
8581004 <groupId>org.codehaus.xsite</groupId>
8591005 <artifactId>xsite-maven-plugin</artifactId>
8601006 <version>${version.plugin.codehaus.xsite}</version>
1007 <dependencies>
1008 <dependency>
1009 <groupId>com.thoughtworks.xstream</groupId>
1010 <artifactId>xstream</artifactId>
1011 <version>1.4.11.1</version>
1012 </dependency>
1013 </dependencies>
8611014 </plugin>
8621015 <plugin>
8631016 <groupId>org.apache.felix</groupId>
8661019 <configuration>
8671020 <manifestLocation>${project.build.directory}/OSGi</manifestLocation>
8681021 <instructions>
1022 <_noee>true</_noee>
8691023 <_nouses>true</_nouses>
8701024 <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
1025 <Bundle-License>BSD-3-Clause</Bundle-License>
8711026 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version><!-- FELIX-3392 -->
8721027 </instructions>
8731028 <archive>
9431098 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9441099
9451100 <version.java.5>1.5</version.java.5>
1101 <version.java.6>1.6</version.java.6>
9461102 <version.java.source>1.5</version.java.source>
9471103 <version.java.target>1.5</version.java.target>
9481104 <version.java.enforced>[1.4,)</version.java.enforced>
9491105
950 <version.plugin.codehaus.xsite>1.2.1</version.plugin.codehaus.xsite>
1106 <version.plugin.codehaus.xsite>1.3</version.plugin.codehaus.xsite>
9511107 <version.plugin.felix.bundle>2.3.7</version.plugin.felix.bundle>
9521108 <version.plugin.maven.antrun>1.1</version.plugin.maven.antrun>
9531109 <version.plugin.maven.assembly>2.1</version.plugin.maven.assembly>
9561112 <version.plugin.maven.dependency>2.1</version.plugin.maven.dependency>
9571113 <version.plugin.maven.deploy>2.3</version.plugin.maven.deploy>
9581114 <version.plugin.maven.enforcer>1.4</version.plugin.maven.enforcer>
1115 <version.plugin.maven.failsafe>2.22.0</version.plugin.maven.failsafe>
9591116 <version.plugin.maven.gpg>1.4</version.plugin.maven.gpg>
9601117 <version.plugin.maven.install>2.2</version.plugin.maven.install>
9611118 <version.plugin.maven.jar>2.2</version.plugin.maven.jar>
9821139 <version.javaassist>3.12.1.GA</version.javaassist>
9831140 <version.javax.activation>1.1.1</version.javax.activation>
9841141 <version.javax.annotation.api>1.3.2</version.javax.annotation.api>
1142 <version.javax.inject>2.4.0</version.javax.inject>
9851143 <version.javax.xml.bind.api>2.3.1</version.javax.xml.bind.api>
9861144 <version.jmock>1.0.1</version.jmock>
9871145 <version.joda-time>1.6</version.joda-time>
9881146 <version.junit>3.8.1</version.junit>
9891147 <version.net.sf.kxml.kxml2>2.3.0</version.net.sf.kxml.kxml2>
1148 <version.org.apache.felix>4.4.1</version.org.apache.felix>
9901149 <version.org.codehaus.jettison>1.2</version.org.codehaus.jettison>
9911150 <version.org.codehaus.woodstox.asl>3.2.7</version.org.codehaus.woodstox.asl>
9921151 <version.org.hibernate.core>4.2.5.Final</version.org.hibernate.core>
9951154 <version.org.jdom2>2.0.5</version.org.jdom2>
9961155 <version.org.json>20080701</version.org.json>
9971156 <version.org.openjdk.jmh>1.21</version.org.openjdk.jmh>
1157 <version.org.ops4j.pax.exam>3.5.0</version.org.ops4j.pax.exam><!-- java 6 -->
9981158 <version.org.slf4j>1.6.1</version.org.slf4j>
999 <version.oro>2.0.8</version.oro>
10001159 <version.stax>1.2.0</version.stax>
10011160 <version.stax.api>1.0.1</version.stax.api>
10021161 <version.xerces.impl>2.8.1</version.xerces.impl>
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
22 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1313 <parent>
1414 <groupId>com.thoughtworks.xstream</groupId>
1515 <artifactId>xstream-parent</artifactId>
16 <version>1.4.11.1</version>
16 <version>1.4.14</version>
1717 </parent>
1818 <artifactId>xstream</artifactId>
1919 <packaging>jar</packaging>
134134 <dependency>
135135 <groupId>com.megginson.sax</groupId>
136136 <artifactId>xml-writer</artifactId>
137 <scope>test</scope>
138 </dependency>
139
140 <dependency>
141 <groupId>oro</groupId>
142 <artifactId>oro</artifactId>
143137 <scope>test</scope>
144138 </dependency>
145139
197191 <configuration>
198192 <includes>
199193 <include>**/AbstractAcceptanceTest.*</include>
194 <include>META-INF/LICENSE</include>
200195 </includes>
201196 <archive combine.children="append">
202197 <manifestEntries>
203198 <Specification-Title>${project.name} Test</Specification-Title>
204199 <Implementation-Title>${project.name} Test</Implementation-Title>
200 <Bundle-License>BSD-3-Clause</Bundle-License>
205201 </manifestEntries>
206202 </archive>
207203 </configuration>
310306 <source>1.8</source>
311307 <target>1.8</target>
312308 <excludes combine.self="override" />
313 <textExcludes combine.self="override" />
309 <testExcludes combine.self="override" />
314310 </configuration>
315311 <goals>
316312 <goal>compile</goal>
592588
593589 <properties>
594590 <bundle.export.package>!com.thoughtworks.xstream.core.util,com.thoughtworks.xstream.*;-noimport:=true</bundle.export.package>
595 <bundle.import.package>org.xmlpull.mxp1;resolution:=optional,org.xmlpull.v1;resolution:=optional,*</bundle.import.package>
591 <bundle.import.package>
592 org.xmlpull.mxp1;resolution:=optional,
593 org.xmlpull.v1;resolution:=optional,
594 com.ibm.*;resolution:=optional,
595 com.sun.*;resolution:=optional,
596 javax.*;resolution:=optional,
597 org.xml.*;resolution:=optional,
598 sun.*;resolution:=optional,
599 *
600 </bundle.import.package>
596601 </properties>
597602
598603 </project>
00 /*
11 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3535 import java.nio.charset.Charset;
3636 import java.text.DecimalFormatSymbols;
3737 import java.util.ArrayList;
38 import java.util.Arrays;
3839 import java.util.BitSet;
3940 import java.util.Calendar;
4041 import java.util.Collection;
6465 import com.thoughtworks.xstream.converters.ConverterLookup;
6566 import com.thoughtworks.xstream.converters.ConverterRegistry;
6667 import com.thoughtworks.xstream.converters.DataHolder;
67 import com.thoughtworks.xstream.converters.MarshallingContext;
6868 import com.thoughtworks.xstream.converters.SingleValueConverter;
6969 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
70 import com.thoughtworks.xstream.converters.UnmarshallingContext;
7170 import com.thoughtworks.xstream.converters.basic.BigDecimalConverter;
7271 import com.thoughtworks.xstream.converters.basic.BigIntegerConverter;
7372 import com.thoughtworks.xstream.converters.basic.BooleanConverter;
178177 *
179178 * </blockquote>
180179 * <hr>
181 *
182180 * <h3>Aliasing classes</h3>
183 *
184181 * <p>
185 * To create shorter XML, you can specify aliases for classes using the <code>alias()</code>
186 * method. For example, you can shorten all occurrences of element
187 * <code>&lt;com.blah.MyThing&gt;</code> to <code>&lt;my-thing&gt;</code> by registering an
188 * alias for the class.
182 * To create shorter XML, you can specify aliases for classes using the <code>alias()</code> method. For example, you
183 * can shorten all occurrences of element <code>&lt;com.blah.MyThing&gt;</code> to <code>&lt;my-thing&gt;</code> by
184 * registering an alias for the class.
189185 * <p>
190186 * <hr>
191187 * <blockquote>
196192 *
197193 * </blockquote>
198194 * <hr>
199 *
200195 * <h3>Converters</h3>
201 *
202196 * <p>
203 * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each
204 * of which acts as a strategy for converting a particular type of class to XML and back again. Out
205 * of the box, XStream contains converters for most basic types (String, Date, int, boolean, etc)
206 * and collections (Map, List, Set, Properties, etc). For other objects reflection is used to
207 * serialize each field recursively.
197 * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each of which acts as a
198 * strategy for converting a particular type of class to XML and back again. Out of the box, XStream contains converters
199 * for most basic types (String, Date, int, boolean, etc) and collections (Map, List, Set, Properties, etc). For other
200 * objects reflection is used to serialize each field recursively.
208201 * </p>
209 *
210202 * <p>
211 * Extra converters can be registered using the <code>registerConverter()</code> method. Some
212 * non-standard converters are supplied in the {@link com.thoughtworks.xstream.converters.extended}
213 * package and you can create your own by implementing the
214 * {@link com.thoughtworks.xstream.converters.Converter} interface.
203 * Extra converters can be registered using the <code>registerConverter()</code> method. Some non-standard converters
204 * are supplied in the {@link com.thoughtworks.xstream.converters.extended} package and you can create your own by
205 * implementing the {@link com.thoughtworks.xstream.converters.Converter} interface.
215206 * </p>
216 *
217207 * <p>
218208 * <hr>
219209 * <b>Example</b><blockquote>
226216 * </blockquote>
227217 * <hr>
228218 * <p>
229 * The converters can be registered with an explicit priority. By default they are registered with
230 * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence
231 * they have been registered. The default converter, i.e. the converter which will be used if
232 * no other registered converter is suitable, can be registered with priority
233 * XStream.PRIORITY_VERY_LOW. XStream uses by default the
234 * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback
235 * converter.
219 * The converters can be registered with an explicit priority. By default they are registered with
220 * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence they have been registered.
221 * The default converter, i.e. the converter which will be used if no other registered converter is suitable, can be
222 * registered with priority XStream.PRIORITY_VERY_LOW. XStream uses by default the
223 * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback converter.
236224 * </p>
237 *
238225 * <p>
239226 * <hr>
240227 * <b>Example</b><blockquote>
245232 *
246233 * </blockquote>
247234 * <hr>
248 *
249235 * <h3>Object graphs</h3>
250 *
251236 * <p>
252 * XStream has support for object graphs; a deserialized object graph will keep references intact,
253 * including circular references.
237 * XStream has support for object graphs; a deserialized object graph will keep references intact, including circular
238 * references.
254239 * </p>
255 *
256240 * <p>
257241 * XStream can signify references in XML using either relative/absolute XPath or IDs. The mode can be changed using
258242 * <code>setMode()</code>:
259243 * </p>
260 *
261244 * <table border='1'>
262245 * <caption></caption>
263246 * <tr>
264247 * <td><code>xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);</code></td>
265 * <td><i>(Default)</i> Uses XPath relative references to signify duplicate references. This produces XML
266 * with the least clutter.</td>
248 * <td><i>(Default)</i> Uses XPath relative references to signify duplicate references. This produces XML with the least
249 * clutter.</td>
267250 * </tr>
268251 * <tr>
269252 * <td><code>xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);</code></td>
270 * <td>Uses XPath absolute references to signify duplicate
271 * references. This produces XML with the least clutter.</td>
253 * <td>Uses XPath absolute references to signify duplicate references. This produces XML with the least clutter.</td>
272254 * </tr>
273255 * <tr>
274256 * <td><code>xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);</code></td>
275 * <td>Uses XPath relative references to signify duplicate references. The XPath expression ensures that
276 * a single node only is selected always.</td>
257 * <td>Uses XPath relative references to signify duplicate references. The XPath expression ensures that a single node
258 * only is selected always.</td>
277259 * </tr>
278260 * <tr>
279261 * <td><code>xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);</code></td>
280 * <td>Uses XPath absolute references to signify duplicate references. The XPath expression ensures that
281 * a single node only is selected always.</td>
262 * <td>Uses XPath absolute references to signify duplicate references. The XPath expression ensures that a single node
263 * only is selected always.</td>
282264 * </tr>
283265 * <tr>
284266 * <td><code>xstream.setMode(XStream.ID_REFERENCES);</code></td>
285 * <td>Uses ID references to signify duplicate references. In some scenarios, such as when using
286 * hand-written XML, this is easier to work with.</td>
267 * <td>Uses ID references to signify duplicate references. In some scenarios, such as when using hand-written XML, this
268 * is easier to work with.</td>
287269 * </tr>
288270 * <tr>
289271 * <td><code>xstream.setMode(XStream.NO_REFERENCES);</code></td>
290 * <td>This disables object graph support and treats the object structure like a tree. Duplicate
291 * references are treated as two separate objects and circular references cause an exception. This
292 * is slightly faster and uses less memory than the other two modes.</td>
272 * <td>This disables object graph support and treats the object structure like a tree. Duplicate references are treated
273 * as two separate objects and circular references cause an exception. This is slightly faster and uses less memory than
274 * the other two modes.</td>
293275 * </tr>
294276 * </table>
295277 * <h3>Thread safety</h3>
296278 * <p>
297 * The XStream instance is thread-safe. That is, once the XStream instance has been created and
298 * configured, it may be shared across multiple threads allowing objects to be
299 * serialized/deserialized concurrently. <em>Note, that this only applies if annotations are not
300 * auto-detected on-the-fly.</em>
279 * The XStream instance is thread-safe. That is, once the XStream instance has been created and configured, it may be
280 * shared across multiple threads allowing objects to be serialized/deserialized concurrently. <em>Note, that this only
281 * applies if annotations are not auto-detected on-the-fly.</em>
301282 * </p>
302283 * <h3>Implicit collections</h3>
303 *
304284 * <p>
305 * To avoid the need for special tags for collections, you can define implicit collections using one
306 * of the <code>addImplicitCollection</code> methods.
285 * To avoid the need for special tags for collections, you can define implicit collections using one of the
286 * <code>addImplicitCollection</code> methods.
307287 * </p>
308288 *
309289 * @author Joe Walnes
354334
355335 private static final String ANNOTATION_MAPPER_TYPE = "com.thoughtworks.xstream.mapper.AnnotationMapper";
356336 private static final Pattern IGNORE_ALL = Pattern.compile(".*");
337 private static final Pattern LAZY_ITERATORS = Pattern.compile(".*\\$LazyIterator");
338 private static final Pattern JAVAX_CRYPTO = Pattern.compile("javax\\.crypto\\..*");
357339
358340 /**
359341 * Constructs a default XStream.
360342 * <p>
361 * The instance will use the {@link XppDriver} as default and tries to determine the best
362 * match for the {@link ReflectionProvider} on its own.
343 * The instance will use the {@link XppDriver} as default and tries to determine the best match for the
344 * {@link ReflectionProvider} on its own.
363345 * </p>
364346 *
365347 * @throws InitializationException in case of an initialization problem
374356 * The instance will use the {@link XppDriver} as default.
375357 * </p>
376358 *
377 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
378 * matching reflection provider
359 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching reflection provider
379360 * @throws InitializationException in case of an initialization problem
380361 */
381362 public XStream(ReflectionProvider reflectionProvider) {
385366 /**
386367 * Constructs an XStream with a special {@link HierarchicalStreamDriver}.
387368 * <p>
388 * The instance will tries to determine the best match for the {@link ReflectionProvider} on
389 * its own.
369 * The instance will tries to determine the best match for the {@link ReflectionProvider} on its own.
390370 * </p>
391371 *
392372 * @param hierarchicalStreamDriver the driver instance
397377 }
398378
399379 /**
400 * Constructs an XStream with a special {@link HierarchicalStreamDriver} and
401 * {@link ReflectionProvider}.
402 *
403 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
404 * matching Provider
380 * Constructs an XStream with a special {@link HierarchicalStreamDriver} and {@link ReflectionProvider}.
381 *
382 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
405383 * @param hierarchicalStreamDriver the driver instance
406384 * @throws InitializationException in case of an initialization problem
407385 */
408 public XStream(
409 ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
386 public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
410387 this(reflectionProvider, (Mapper)null, hierarchicalStreamDriver);
411388 }
412389
413390 /**
414 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
415 * {@link ReflectionProvider} and a prepared {@link Mapper} chain.
416 *
417 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
418 * matching Provider
419 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
420 * chain
391 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and a prepared
392 * {@link Mapper} chain.
393 *
394 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
395 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
421396 * @param driver the driver instance
422397 * @throws InitializationException in case of an initialization problem
423 * @deprecated As of 1.3, use
424 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
398 * @deprecated As of 1.3, use {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
425399 * instead
426400 */
427 public XStream(
428 ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
401 public XStream(ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
429402 this(reflectionProvider, driver, new CompositeClassLoader(), mapper);
430403 }
431404
432405 /**
433 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
434 * {@link ReflectionProvider} and a {@link ClassLoaderReference}.
435 *
436 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
437 * matching Provider
406 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and a
407 * {@link ClassLoaderReference}.
408 *
409 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
438410 * @param driver the driver instance
439411 * @param classLoaderReference the reference to the {@link ClassLoader} to use
440412 * @throws InitializationException in case of an initialization problem
441413 * @since 1.4.5
442414 */
443415 public XStream(
444 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
445 ClassLoaderReference classLoaderReference) {
416 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
417 ClassLoaderReference classLoaderReference) {
446418 this(reflectionProvider, driver, classLoaderReference, null);
447419 }
448420
449421 /**
450 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
451 * {@link ReflectionProvider} and the {@link ClassLoader} to use.
422 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and the
423 * {@link ClassLoader} to use.
452424 *
453425 * @throws InitializationException in case of an initialization problem
454426 * @since 1.3
455 * @deprecated As of 1.4.5 use
456 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
457 */
458 public XStream(
459 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
460 ClassLoader classLoader) {
427 * @deprecated As of 1.4.5 use {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
428 */
429 public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoader classLoader) {
461430 this(reflectionProvider, driver, classLoader, null);
462431 }
463432
464433 /**
465 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
466 * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the {@link ClassLoader}
467 * to use.
468 *
469 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
470 * matching Provider
434 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
435 * {@link Mapper} chain and the {@link ClassLoader} to use.
436 *
437 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
471438 * @param driver the driver instance
472439 * @param classLoader the {@link ClassLoader} to use
473 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
474 * chain
440 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
475441 * @throws InitializationException in case of an initialization problem
476442 * @since 1.3
477443 * @deprecated As of 1.4.5 use
478444 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper)}
479445 */
480446 public XStream(
481 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
482 ClassLoader classLoader, Mapper mapper) {
483 this(
484 reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
485 }
486
487 /**
488 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
489 * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the
490 * {@link ClassLoaderReference}.
447 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoader classLoader,
448 Mapper mapper) {
449 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
450 }
451
452 /**
453 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
454 * {@link Mapper} chain and the {@link ClassLoaderReference}.
491455 * <p>
492456 * The {@link ClassLoaderReference} should also be used for the {@link Mapper} chain.
493457 * </p>
494458 *
495 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
496 * matching Provider
459 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
497460 * @param driver the driver instance
498461 * @param classLoaderReference the reference to the {@link ClassLoader} to use
499 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
500 * chain
462 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
501463 * @throws InitializationException in case of an initialization problem
502464 * @since 1.4.5
503465 */
504466 public XStream(
505 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
506 ClassLoaderReference classLoaderReference, Mapper mapper) {
507 this(
508 reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
509 }
510
467 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
468 ClassLoaderReference classLoaderReference, Mapper mapper) {
469 this(reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
470 }
471
511472 private XStream(
512473 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
513474 Mapper mapper, final DefaultConverterLookup defaultConverterLookup) {
523484 }
524485
525486 /**
526 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
527 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
528 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
487 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
488 * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and
529489 * {@link ConverterRegistry}.
530490 *
531 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
532 * matching Provider
491 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
533492 * @param driver the driver instance
534493 * @param classLoader the {@link ClassLoader} to use
535 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
536 * chain
494 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
537495 * @param converterLookup the instance that is used to lookup the converters
538496 * @param converterRegistry an instance to manage the converter instances
539497 * @throws InitializationException in case of an initialization problem
542500 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper, ConverterLookup, ConverterRegistry)}
543501 */
544502 public XStream(
545 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
546 ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup,
547 ConverterRegistry converterRegistry) {
548 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup, converterRegistry);
549 }
550
551 /**
552 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
553 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
554 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
503 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoader classLoader,
504 Mapper mapper, ConverterLookup converterLookup, ConverterRegistry converterRegistry) {
505 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup,
506 converterRegistry);
507 }
508
509 /**
510 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
511 * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and
555512 * {@link ConverterRegistry}.
556513 * <p>
557 * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup
558 * should access the ConverterRegistry if you intent to register {@link Converter} instances
559 * with XStream facade or you are using annotations.
514 * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup should access the
515 * ConverterRegistry if you intent to register {@link Converter} instances with XStream facade or you are using
516 * annotations.
560517 * </p>
561518 *
562 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
563 * matching Provider
519 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
564520 * @param driver the driver instance
565521 * @param classLoaderReference the reference to the {@link ClassLoader} to use
566 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
567 * chain
522 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
568523 * @param converterLookup the instance that is used to lookup the converters
569 * @param converterRegistry an instance to manage the converter instances or <em>null</em>
570 * to prevent any further registry (including annotations)
524 * @param converterRegistry an instance to manage the converter instances or <em>null</em> to prevent any further
525 * registry (including annotations)
571526 * @throws InitializationException in case of an initialization problem
572527 * @since 1.4.5
573528 */
574529 public XStream(
575 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
576 ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
577 ConverterRegistry converterRegistry) {
530 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
531 ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
532 ConverterRegistry converterRegistry) {
578533 if (reflectionProvider == null) {
579534 reflectionProvider = JVM.newReflectionProvider();
580535 }
612567 mapper = new DefaultImplementationsMapper(mapper);
613568 mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider);
614569 if (JVM.isVersion(5)) {
615 mapper = buildMapperDynamically(
616 "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
570 mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
617571 new Object[]{mapper});
618572 }
619573 mapper = new LocalConversionMapper(mapper);
625579 mapper = new SecurityMapper(mapper);
626580 if (JVM.isVersion(5)) {
627581 mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{
628 Mapper.class, ConverterRegistry.class, ConverterLookup.class,
629 ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{
630 mapper, converterRegistry, converterLookup, classLoaderReference,
631 reflectionProvider});
582 Mapper.class, ConverterRegistry.class, ConverterLookup.class, ClassLoaderReference.class,
583 ReflectionProvider.class}, new Object[]{
584 mapper, converterRegistry, converterLookup, classLoaderReference, reflectionProvider});
632585 }
633586 mapper = wrapMapper((MapperWrapper)mapper);
634587 mapper = new CachingMapper(mapper);
636589 }
637590
638591 private Mapper buildMapperDynamically(String className, Class[] constructorParamTypes,
639 Object[] constructorParamValues) {
592 Object[] constructorParamValues) {
640593 try {
641594 Class type = Class.forName(className, false, classLoaderReference.getReference());
642595 Constructor constructor = type.getConstructor(constructorParamTypes);
643596 return (Mapper)constructor.newInstance(constructorParamValues);
644597 } catch (Exception e) {
645 throw new com.thoughtworks.xstream.InitializationException(
646 "Could not instantiate mapper : " + className, e);
598 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate mapper : " + className,
599 e);
647600 } catch (LinkageError e) {
648 throw new com.thoughtworks.xstream.InitializationException(
649 "Could not instantiate mapper : " + className, e);
601 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate mapper : " + className,
602 e);
650603 }
651604 }
652605
662615 }
663616
664617 private void setupMappers() {
665 packageAliasingMapper = (PackageAliasingMapper)this.mapper
666 .lookupMapperOfType(PackageAliasingMapper.class);
667 classAliasingMapper = (ClassAliasingMapper)this.mapper
668 .lookupMapperOfType(ClassAliasingMapper.class);
669 elementIgnoringMapper = (ElementIgnoringMapper)this.mapper
670 .lookupMapperOfType(ElementIgnoringMapper.class);
671 fieldAliasingMapper = (FieldAliasingMapper)this.mapper
672 .lookupMapperOfType(FieldAliasingMapper.class);
673 attributeMapper = (AttributeMapper)this.mapper
674 .lookupMapperOfType(AttributeMapper.class);
618 packageAliasingMapper = (PackageAliasingMapper)this.mapper.lookupMapperOfType(PackageAliasingMapper.class);
619 classAliasingMapper = (ClassAliasingMapper)this.mapper.lookupMapperOfType(ClassAliasingMapper.class);
620 elementIgnoringMapper = (ElementIgnoringMapper)this.mapper.lookupMapperOfType(ElementIgnoringMapper.class);
621 fieldAliasingMapper = (FieldAliasingMapper)this.mapper.lookupMapperOfType(FieldAliasingMapper.class);
622 attributeMapper = (AttributeMapper)this.mapper.lookupMapperOfType(AttributeMapper.class);
675623 attributeAliasingMapper = (AttributeAliasingMapper)this.mapper
676624 .lookupMapperOfType(AttributeAliasingMapper.class);
677625 systemAttributeAliasingMapper = (SystemAttributeAliasingMapper)this.mapper
680628 .lookupMapperOfType(ImplicitCollectionMapper.class);
681629 defaultImplementationsMapper = (DefaultImplementationsMapper)this.mapper
682630 .lookupMapperOfType(DefaultImplementationsMapper.class);
683 immutableTypesMapper = (ImmutableTypesMapper)this.mapper
684 .lookupMapperOfType(ImmutableTypesMapper.class);
685 localConversionMapper = (LocalConversionMapper)this.mapper
686 .lookupMapperOfType(LocalConversionMapper.class);
687 securityMapper = (SecurityMapper)this.mapper
688 .lookupMapperOfType(SecurityMapper.class);
631 immutableTypesMapper = (ImmutableTypesMapper)this.mapper.lookupMapperOfType(ImmutableTypesMapper.class);
632 localConversionMapper = (LocalConversionMapper)this.mapper.lookupMapperOfType(LocalConversionMapper.class);
633 securityMapper = (SecurityMapper)this.mapper.lookupMapperOfType(SecurityMapper.class);
689634 annotationConfiguration = (AnnotationConfiguration)this.mapper
690635 .lookupMapperOfType(AnnotationConfiguration.class);
691636 }
692
637
693638 protected void setupSecurity() {
694639 if (securityMapper == null) {
695640 return;
696641 }
697
642
698643 addPermission(AnyTypePermission.ANY);
644 denyTypes(new String[]{"java.beans.EventHandler", "java.lang.ProcessBuilder", "javax.imageio.ImageIO$ContainsFilter"});
645 denyTypesByRegExp(new Pattern[]{LAZY_ITERATORS, JAVAX_CRYPTO});
646 allowTypeHierarchy(Exception.class);
699647 securityInitialized = false;
700648 }
701649
839787 alias("tree-map", TreeMap.class);
840788 alias("tree-set", TreeSet.class);
841789 alias("hashtable", Hashtable.class);
842
790
843791 alias("empty-list", Collections.EMPTY_LIST.getClass());
844792 alias("empty-map", Collections.EMPTY_MAP.getClass());
845793 alias("empty-set", Collections.EMPTY_SET.getClass());
888836 alias("string-builder", JVM.loadClassForName("java.lang.StringBuilder"));
889837 alias("uuid", JVM.loadClassForName("java.util.UUID"));
890838 }
891
839
892840 if (JVM.isVersion(7)) {
893841 aliasType("path", JVM.loadClassForName("java.nio.file.Path"));
894842 }
955903 }
956904
957905 protected void setupConverters() {
958 registerConverter(
959 new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
960
961 registerConverter(
962 new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
906 registerConverter(new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
907
908 registerConverter(new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
963909 registerConverter(new ExternalizableConverter(mapper, classLoaderReference), PRIORITY_LOW);
964 registerConverter(new InternalBlackList(), PRIORITY_LOW);
965910
966911 registerConverter(new NullConverter(), PRIORITY_VERY_HIGH);
967912 registerConverter(new IntConverter(), PRIORITY_NORMAL);
1010955 registerConverter(new TextAttributeConverter(), PRIORITY_NORMAL);
1011956 }
1012957 if (JVM.isSwingAvailable()) {
1013 registerConverter(
1014 new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
958 registerConverter(new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
1015959 }
1016960 registerConverter(new LocaleConverter(), PRIORITY_NORMAL);
1017961 registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL);
1018962
1019963 if (JVM.isVersion(4)) {
1020964 // late bound converters - allows XStream to be compiled on earlier JDKs
1021 registerConverterDynamically(
1022 "com.thoughtworks.xstream.converters.extended.SubjectConverter",
965 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.SubjectConverter",
1023966 PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
1024 registerConverterDynamically(
1025 "com.thoughtworks.xstream.converters.extended.ThrowableConverter",
1026 PRIORITY_NORMAL, new Class[]{ConverterLookup.class},
1027 new Object[]{converterLookup});
1028 registerConverterDynamically(
1029 "com.thoughtworks.xstream.converters.extended.StackTraceElementConverter",
967 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.ThrowableConverter",
968 PRIORITY_NORMAL, new Class[]{ConverterLookup.class}, new Object[]{converterLookup});
969 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.StackTraceElementConverter",
1030970 PRIORITY_NORMAL, null, null);
1031 registerConverterDynamically(
1032 "com.thoughtworks.xstream.converters.extended.CurrencyConverter",
971 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.CurrencyConverter",
1033972 PRIORITY_NORMAL, null, null);
1034 registerConverterDynamically(
1035 "com.thoughtworks.xstream.converters.extended.RegexPatternConverter",
973 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.RegexPatternConverter",
1036974 PRIORITY_NORMAL, null, null);
1037 registerConverterDynamically(
1038 "com.thoughtworks.xstream.converters.extended.CharsetConverter",
975 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.CharsetConverter",
1039976 PRIORITY_NORMAL, null, null);
1040977 }
1041978
1042979 if (JVM.isVersion(5)) {
1043980 // late bound converters - allows XStream to be compiled on earlier JDKs
1044981 if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) {
1045 registerConverterDynamically(
1046 "com.thoughtworks.xstream.converters.extended.DurationConverter",
982 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.DurationConverter",
1047983 PRIORITY_NORMAL, null, null);
1048984 }
1049 registerConverterDynamically(
1050 "com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL,
985 registerConverterDynamically("com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL,
1051986 null, null);
1052 registerConverterDynamically(
1053 "com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL,
987 registerConverterDynamically("com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL,
1054988 new Class[]{Mapper.class}, new Object[]{mapper});
1055 registerConverterDynamically(
1056 "com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL,
989 registerConverterDynamically("com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL,
1057990 new Class[]{Mapper.class}, new Object[]{mapper});
1058 registerConverterDynamically(
1059 "com.thoughtworks.xstream.converters.basic.StringBuilderConverter",
991 registerConverterDynamically("com.thoughtworks.xstream.converters.basic.StringBuilderConverter",
1060992 PRIORITY_NORMAL, null, null);
1061 registerConverterDynamically(
1062 "com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
993 registerConverterDynamically("com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
1063994 null, null);
1064995 }
1065996 if (JVM.loadClassForName("javax.activation.ActivationDataFlavor") != null) {
1067998 PRIORITY_NORMAL, null, null);
1068999 }
10691000 if (JVM.isVersion(7)) {
1070 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter",
1071 PRIORITY_NORMAL, null, null);
1001 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter", PRIORITY_NORMAL,
1002 null, null);
10721003 }
10731004 if (JVM.isVersion(8)) {
10741005 registerConverterDynamically("com.thoughtworks.xstream.converters.time.ChronologyConverter",
11201051 new Object[]{mapper, reflectionProvider, classLoaderReference});
11211052 }
11221053
1123 registerConverter(
1124 new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
1125 }
1126
1127 private void registerConverterDynamically(String className, int priority,
1128 Class[] constructorParamTypes, Object[] constructorParamValues) {
1054 registerConverter(new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
1055 }
1056
1057 private void registerConverterDynamically(String className, int priority, Class[] constructorParamTypes,
1058 Object[] constructorParamValues) {
11291059 try {
11301060 Class type = Class.forName(className, false, classLoaderReference.getReference());
11311061 Constructor constructor = type.getConstructor(constructorParamTypes);
11361066 registerConverter((SingleValueConverter)instance, priority);
11371067 }
11381068 } catch (Exception e) {
1139 throw new com.thoughtworks.xstream.InitializationException(
1140 "Could not instantiate converter : " + className, e);
1069 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate converter : " + className,
1070 e);
11411071 } catch (LinkageError e) {
1142 throw new com.thoughtworks.xstream.InitializationException(
1143 "Could not instantiate converter : " + className, e);
1072 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate converter : " + className,
1073 e);
11441074 }
11451075 }
11461076
11811111 if (type != null) {
11821112 Method methodGet;
11831113 try {
1184 methodGet = type.getDeclaredMethod("get", new Class[] {String.class, String[].class});
1114 methodGet = type.getDeclaredMethod("get", new Class[]{String.class, String[].class});
11851115 if (methodGet != null) {
11861116 Object path = methodGet.invoke(null, new Object[]{".", new String[0]});
11871117 if (path != null) {
12051135 addImmutableTypeDynamically("java.nio.charset.Charset", true);
12061136 addImmutableTypeDynamically("java.util.Currency", true);
12071137 }
1208
1138
12091139 if (JVM.isVersion(5)) {
12101140 addImmutableTypeDynamically("java.util.UUID", true);
12111141 }
12701200 }
12711201
12721202 /**
1273 * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed
1274 * afterwards and in case of an exception.
1203 * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed afterwards and in case
1204 * of an exception.
12751205 *
12761206 * @throws XStreamException if the object cannot be serialized
12771207 */
12851215 }
12861216
12871217 /**
1288 * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream
1289 * will be flushed afterwards and in case of an exception.
1218 * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream will be flushed afterwards
1219 * and in case of an exception.
12901220 *
12911221 * @throws XStreamException if the object cannot be serialized
12921222 */
13111241 /**
13121242 * Serialize and object to a hierarchical data structure (such as XML).
13131243 *
1314 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
1315 * want. If not present, XStream shall create one lazily as needed.
1244 * @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
1245 * XStream shall create one lazily as needed.
13161246 * @throws XStreamException if the object cannot be serialized
13171247 */
13181248 public void marshal(Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder) {
13471277 }
13481278
13491279 /**
1350 * Deserialize an object from a URL.
1351 *
1352 * Depending on the parser implementation, some might take the file path as SystemId to
1353 * resolve additional references.
1280 * Deserialize an object from a URL. Depending on the parser implementation, some might take the file path as
1281 * SystemId to resolve additional references.
13541282 *
13551283 * @throws XStreamException if the object cannot be deserialized
13561284 * @since 1.4
13601288 }
13611289
13621290 /**
1363 * Deserialize an object from a file.
1364 *
1365 * Depending on the parser implementation, some might take the file path as SystemId to
1366 * resolve additional references.
1291 * Deserialize an object from a file. Depending on the parser implementation, some might take the file path as
1292 * SystemId to resolve additional references.
13671293 *
13681294 * @throws XStreamException if the object cannot be deserialized
13691295 * @since 1.4
13731299 }
13741300
13751301 /**
1376 * Deserialize an object from an XML String, populating the fields of the given root object
1377 * instead of instantiating a new one. Note, that this is a special use case! With the
1378 * ReflectionConverter XStream will write directly into the raw memory area of the existing
1379 * object. Use with care!
1302 * Deserialize an object from an XML String, populating the fields of the given root object instead of instantiating
1303 * a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into
1304 * the raw memory area of the existing object. Use with care!
13801305 *
13811306 * @throws XStreamException if the object cannot be deserialized
13821307 */
13851310 }
13861311
13871312 /**
1388 * Deserialize an object from an XML Reader, populating the fields of the given root object
1389 * instead of instantiating a new one. Note, that this is a special use case! With the
1390 * ReflectionConverter XStream will write directly into the raw memory area of the existing
1391 * object. Use with care!
1313 * Deserialize an object from an XML Reader, populating the fields of the given root object instead of instantiating
1314 * a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into
1315 * the raw memory area of the existing object. Use with care!
13921316 *
13931317 * @throws XStreamException if the object cannot be deserialized
13941318 */
13971321 }
13981322
13991323 /**
1400 * Deserialize an object from a URL, populating the fields of the given root
1401 * object instead of instantiating a new one. Note, that this is a special use case! With
1402 * the ReflectionConverter XStream will write directly into the raw memory area of the
1403 * existing object. Use with care!
1404 *
1405 * Depending on the parser implementation, some might take the file path as SystemId to
1406 * resolve additional references.
1324 * Deserialize an object from a URL, populating the fields of the given root object instead of instantiating a new
1325 * one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
1326 * memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
1327 * file path as SystemId to resolve additional references.
14071328 *
14081329 * @throws XStreamException if the object cannot be deserialized
14091330 * @since 1.4
14131334 }
14141335
14151336 /**
1416 * Deserialize an object from a file, populating the fields of the given root
1417 * object instead of instantiating a new one. Note, that this is a special use case! With
1418 * the ReflectionConverter XStream will write directly into the raw memory area of the
1419 * existing object. Use with care!
1420 *
1421 * Depending on the parser implementation, some might take the file path as SystemId to
1422 * resolve additional references.
1337 * Deserialize an object from a file, populating the fields of the given root object instead of instantiating a new
1338 * one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
1339 * memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
1340 * file path as SystemId to resolve additional references.
14231341 *
14241342 * @throws XStreamException if the object cannot be deserialized
14251343 * @since 1.4
14341352 }
14351353
14361354 /**
1437 * Deserialize an object from an XML InputStream, populating the fields of the given root
1438 * object instead of instantiating a new one. Note, that this is a special use case! With
1439 * the ReflectionConverter XStream will write directly into the raw memory area of the
1440 * existing object. Use with care!
1355 * Deserialize an object from an XML InputStream, populating the fields of the given root object instead of
1356 * instantiating a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write
1357 * directly into the raw memory area of the existing object. Use with care!
14411358 *
14421359 * @throws XStreamException if the object cannot be deserialized
14431360 */
14551372 }
14561373
14571374 /**
1458 * Deserialize an object from a hierarchical data structure (such as XML), populating the
1459 * fields of the given root object instead of instantiating a new one. Note, that this is a
1460 * special use case! With the ReflectionConverter XStream will write directly into the raw
1461 * memory area of the existing object. Use with care!
1375 * Deserialize an object from a hierarchical data structure (such as XML), populating the fields of the given root
1376 * object instead of instantiating a new one. Note, that this is a special use case! With the ReflectionConverter
1377 * XStream will write directly into the raw memory area of the existing object. Use with care!
14621378 *
14631379 * @throws XStreamException if the object cannot be deserialized
14641380 */
14691385 /**
14701386 * Deserialize an object from a hierarchical data structure (such as XML).
14711387 *
1472 * @param root If present, the passed in object will have its fields populated, as opposed
1473 * to XStream creating a new instance. Note, that this is a special use case!
1474 * With the ReflectionConverter XStream will write directly into the raw memory
1475 * area of the existing object. Use with care!
1476 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
1477 * want. If not present, XStream shall create one lazily as needed.
1388 * @param root If present, the passed in object will have its fields populated, as opposed to XStream creating a new
1389 * instance. Note, that this is a special use case! With the ReflectionConverter XStream will write
1390 * directly into the raw memory area of the existing object. Use with care!
1391 * @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
1392 * XStream shall create one lazily as needed.
14781393 * @throws XStreamException if the object cannot be deserialized
14791394 */
14801395 public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
14811396 try {
14821397 if (!securityInitialized && !securityWarningGiven) {
14831398 securityWarningGiven = true;
1484 System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable.");
1399 System.err
1400 .println(
1401 "Security framework of XStream not explicitly initialized, using predefined black list on your own risk.");
14851402 }
1486 return marshallingStrategy.unmarshal(
1487 root, reader, dataHolder, converterLookup, mapper);
1403 return marshallingStrategy.unmarshal(root, reader, dataHolder, converterLookup, mapper);
14881404
14891405 } catch (ConversionException e) {
14901406 Package pkg = getClass().getPackage();
15111427 }
15121428
15131429 /**
1514 * Alias a type to a shorter name to be used in XML elements. Any class that is assignable
1515 * to this type will be aliased to the same name.
1430 * Alias a type to a shorter name to be used in XML elements. Any class that is assignable to this type will be
1431 * aliased to the same name.
15161432 *
15171433 * @param name Short name
15181434 * @param type Type to be aliased
15341450 * @param name Short name
15351451 * @param type Type to be aliased
15361452 * @param defaultImplementation Default implementation of type to use if no other specified.
1537 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
1538 * {@link ClassAliasingMapper} is available
1453 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link ClassAliasingMapper} is
1454 * available
15391455 */
15401456 public void alias(String name, Class type, Class defaultImplementation) {
15411457 alias(name, type);
15471463 *
15481464 * @param name Short name
15491465 * @param pkgName package to be aliased
1550 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
1551 * {@link PackageAliasingMapper} is available
1466 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link PackageAliasingMapper} is
1467 * available
15521468 * @since 1.3.1
15531469 */
15541470 public void aliasPackage(String name, String pkgName) {
15941510 }
15951511
15961512 /**
1597 * Create an alias for a system attribute. XStream will not write a system attribute if its
1598 * alias is set to <code>null</code>. However, this is not reversible, i.e. deserialization
1599 * of the result is likely to fail afterwards and will not produce an object equal to the
1600 * originally written one.
1513 * Create an alias for a system attribute. XStream will not write a system attribute if its alias is set to
1514 * <code>null</code>. However, this is not reversible, i.e. deserialization of the result is likely to fail
1515 * afterwards and will not produce an object equal to the originally written one.
16011516 *
16021517 * @param alias the alias itself (may be <code>null</code>)
16031518 * @param systemAttributeName the name of the system attribute
16781593 }
16791594
16801595 /**
1681 * Associate a default implementation of a class with an object. Whenever XStream encounters
1682 * an instance of this type, it will use the default implementation instead. For example,
1683 * java.util.ArrayList is the default implementation of java.util.List.
1596 * Associate a default implementation of a class with an object. Whenever XStream encounters an instance of this
1597 * type, it will use the default implementation instead. For example, java.util.ArrayList is the default
1598 * implementation of java.util.List.
16841599 *
16851600 * @param defaultImplementation
16861601 * @param ofType
17461661
17471662 public void registerConverter(SingleValueConverter converter, int priority) {
17481663 if (converterRegistry != null) {
1749 converterRegistry.registerConverter(
1750 new SingleValueConverterWrapper(converter), priority);
1664 converterRegistry.registerConverter(new SingleValueConverterWrapper(converter), priority);
17511665 }
17521666 }
17531667
17761690 * @param converter the converter to use
17771691 * @since 1.3
17781692 */
1779 public void registerLocalConverter(Class definedIn, String fieldName,
1780 SingleValueConverter converter) {
1781 registerLocalConverter(
1782 definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter));
1783 }
1784
1785 /**
1786 * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper
1787 * MapperWrappers}.
1693 public void registerLocalConverter(Class definedIn, String fieldName, SingleValueConverter converter) {
1694 registerLocalConverter(definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter));
1695 }
1696
1697 /**
1698 * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper MapperWrappers}.
17881699 *
17891700 * @return the mapper
17901701 * @since 1.2
18081719 }
18091720
18101721 /**
1811 * Change mode for dealing with duplicate references. Valid values are
1812 * <code>XPATH_ABSOLUTE_REFERENCES</code>, <code>XPATH_RELATIVE_REFERENCES</code>,
1813 * <code>XStream.ID_REFERENCES</code> and <code>XStream.NO_REFERENCES</code>.
1722 * Change mode for dealing with duplicate references. Valid values are <code>XPATH_ABSOLUTE_REFERENCES</code>,
1723 * <code>XPATH_RELATIVE_REFERENCES</code>, <code>XStream.ID_REFERENCES</code> and
1724 * <code>XStream.NO_REFERENCES</code>.
18141725 *
18151726 * @throws IllegalArgumentException if the mode is not one of the declared types
18161727 * @see #XPATH_ABSOLUTE_REFERENCES
18351746 ReferenceByXPathMarshallingStrategy.ABSOLUTE));
18361747 break;
18371748 case SINGLE_NODE_XPATH_RELATIVE_REFERENCES:
1838 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1839 ReferenceByXPathMarshallingStrategy.RELATIVE
1749 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE
18401750 | ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
18411751 break;
18421752 case SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES:
1843 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1844 ReferenceByXPathMarshallingStrategy.ABSOLUTE
1753 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.ABSOLUTE
18451754 | ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
18461755 break;
18471756 default:
18531762 * Adds a default implicit collection which is used for any unmapped XML tag.
18541763 *
18551764 * @param ownerType class owning the implicit collection
1856 * @param fieldName name of the field in the ownerType. This field must be a concrete
1857 * collection type or matching the default implementation type of the collection
1858 * type.
1765 * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
1766 * the default implementation type of the collection type.
18591767 */
18601768 public void addImplicitCollection(Class ownerType, String fieldName) {
18611769 addImplicitCollection(ownerType, fieldName, null, null);
18651773 * Adds implicit collection which is used for all items of the given itemType.
18661774 *
18671775 * @param ownerType class owning the implicit collection
1868 * @param fieldName name of the field in the ownerType. This field must be a concrete
1869 * collection type or matching the default implementation type of the collection
1870 * type.
1776 * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
1777 * the default implementation type of the collection type.
18711778 * @param itemType type of the items to be part of this collection
18721779 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
18731780 */
18761783 }
18771784
18781785 /**
1879 * Adds implicit collection which is used for all items of the given element name defined by
1880 * itemFieldName.
1786 * Adds implicit collection which is used for all items of the given element name defined by itemFieldName.
18811787 *
18821788 * @param ownerType class owning the implicit collection
1883 * @param fieldName name of the field in the ownerType. This field must be a concrete
1884 * collection type or matching the default implementation type of the collection
1885 * type.
1789 * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
1790 * the default implementation type of the collection type.
18861791 * @param itemFieldName element name of the implicit collection
18871792 * @param itemType item type to be aliases be the itemFieldName
18881793 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
18891794 */
1890 public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName,
1891 Class itemType) {
1795 public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName, Class itemType) {
18921796 addImplicitMap(ownerType, fieldName, itemFieldName, itemType, null);
18931797 }
18941798
18971801 *
18981802 * @param ownerType class owning the implicit array
18991803 * @param fieldName name of the array field
1900 * @since 1.4
1804 * @since 1.4
19011805 */
19021806 public void addImplicitArray(Class ownerType, String fieldName) {
19031807 addImplicitCollection(ownerType, fieldName);
19041808 }
19051809
19061810 /**
1907 * Adds an implicit array which is used for all items of the given itemType when the array
1908 * type matches.
1811 * Adds an implicit array which is used for all items of the given itemType when the array type matches.
19091812 *
19101813 * @param ownerType class owning the implicit array
19111814 * @param fieldName name of the array field in the ownerType
19121815 * @param itemType type of the items to be part of this array
1913 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the
1914 * array type does not match the itemType
1915 * @since 1.4
1816 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the array type does not
1817 * match the itemType
1818 * @since 1.4
19161819 */
19171820 public void addImplicitArray(Class ownerType, String fieldName, Class itemType) {
19181821 addImplicitCollection(ownerType, fieldName, itemType);
19191822 }
19201823
19211824 /**
1922 * Adds an implicit array which is used for all items of the given element name defined by
1923 * itemName.
1825 * Adds an implicit array which is used for all items of the given element name defined by itemName.
19241826 *
19251827 * @param ownerType class owning the implicit array
19261828 * @param fieldName name of the array field in the ownerType
19271829 * @param itemName alias name of the items
19281830 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
1929 * @since 1.4
1831 * @since 1.4
19301832 */
19311833 public void addImplicitArray(Class ownerType, String fieldName, String itemName) {
19321834 addImplicitCollection(ownerType, fieldName, itemName, null);
19361838 * Adds an implicit map.
19371839 *
19381840 * @param ownerType class owning the implicit map
1939 * @param fieldName name of the field in the ownerType. This field must be a concrete
1940 * map type or matching the default implementation type of the map
1941 * type.
1841 * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the
1842 * default implementation type of the map type.
19421843 * @param itemType type of the items to be part of this map as value
19431844 * @param keyFieldName the name of the field of the itemType that is used for the key in the map
1944 * @since 1.4
1845 * @since 1.4
19451846 */
19461847 public void addImplicitMap(Class ownerType, String fieldName, Class itemType, String keyFieldName) {
19471848 addImplicitMap(ownerType, fieldName, null, itemType, keyFieldName);
19511852 * Adds an implicit map.
19521853 *
19531854 * @param ownerType class owning the implicit map
1954 * @param fieldName name of the field in the ownerType. This field must be a concrete
1955 * map type or matching the default implementation type of the map
1956 * type.
1855 * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the
1856 * default implementation type of the map type.
19571857 * @param itemName alias name of the items
19581858 * @param itemType type of the items to be part of this map as value
19591859 * @param keyFieldName the name of the field of the itemType that is used for the key in the map
1960 * @since 1.4
1961 */
1962 public void addImplicitMap(Class ownerType, String fieldName, String itemName,
1963 Class itemType, String keyFieldName) {
1860 * @since 1.4
1861 */
1862 public void addImplicitMap(Class ownerType, String fieldName, String itemName, Class itemType,
1863 String keyFieldName) {
19641864 if (implicitCollectionMapper == null) {
19651865 throw new com.thoughtworks.xstream.InitializationException("No "
19661866 + ImplicitCollectionMapper.class.getName()
19831883 }
19841884
19851885 /**
1986 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
1987 * XStream.
1886 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
19881887 * <p>
19891888 * To change the name of the root element (from &lt;object-stream&gt;), use
19901889 * {@link #createObjectOutputStream(java.io.Writer, String)}.
19911890 * </p>
19921891 *
1993 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1994 * String)
1892 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
19951893 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
19961894 * @since 1.0.3
19971895 */
19981896 public ObjectOutputStream createObjectOutputStream(Writer writer) throws IOException {
1999 return createObjectOutputStream(
2000 hierarchicalStreamDriver.createWriter(writer), "object-stream");
2001 }
2002
2003 /**
2004 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
2005 * XStream.
1897 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), "object-stream");
1898 }
1899
1900 /**
1901 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
20061902 * <p>
20071903 * To change the name of the root element (from &lt;object-stream&gt;), use
20081904 * {@link #createObjectOutputStream(java.io.Writer, String)}.
20091905 * </p>
20101906 *
2011 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2012 * String)
1907 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20131908 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20141909 * @since 1.0.3
20151910 */
2016 public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer)
2017 throws IOException {
1911 public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer) throws IOException {
20181912 return createObjectOutputStream(writer, "object-stream");
20191913 }
20201914
20211915 /**
2022 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
2023 * XStream.
2024 *
2025 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2026 * String)
1916 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
1917 *
1918 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20271919 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20281920 * @since 1.0.3
20291921 */
2030 public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName)
2031 throws IOException {
2032 return createObjectOutputStream(
2033 hierarchicalStreamDriver.createWriter(writer), rootNodeName);
2034 }
2035
2036 /**
2037 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
2038 * using XStream.
1922 public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName) throws IOException {
1923 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName);
1924 }
1925
1926 /**
1927 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.
20391928 * <p>
20401929 * To change the name of the root element (from &lt;object-stream&gt;), use
20411930 * {@link #createObjectOutputStream(java.io.Writer, String)}.
20421931 * </p>
20431932 *
2044 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2045 * String)
1933 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20461934 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20471935 * @since 1.3
20481936 */
20491937 public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException {
2050 return createObjectOutputStream(
2051 hierarchicalStreamDriver.createWriter(out), "object-stream");
2052 }
2053
2054 /**
2055 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
2056 * using XStream.
2057 *
2058 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2059 * String)
1938 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), "object-stream");
1939 }
1940
1941 /**
1942 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.
1943 *
1944 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20601945 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20611946 * @since 1.3
20621947 */
2063 public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName)
2064 throws IOException {
2065 return createObjectOutputStream(
2066 hierarchicalStreamDriver.createWriter(out), rootNodeName);
2067 }
2068
2069 /**
2070 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
2071 * XStream.
1948 public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName) throws IOException {
1949 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName);
1950 }
1951
1952 /**
1953 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
20721954 * <p>
2073 * Because an ObjectOutputStream can contain multiple items and XML only allows a single
2074 * root node, the stream must be written inside an enclosing node.
1955 * Because an ObjectOutputStream can contain multiple items and XML only allows a single root node, the stream must
1956 * be written inside an enclosing node.
20751957 * </p>
20761958 * <p>
2077 * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will
2078 * be incomplete.
1959 * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will be incomplete.
20791960 * </p>
20801961 * <h3>Example</h3>
20811962 *
21051986 * @since 1.4.10
21061987 */
21071988 public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName,
2108 final DataHolder dataHolder) throws IOException {
1989 final DataHolder dataHolder)
1990 throws IOException {
21091991 final StatefulWriter statefulWriter = new StatefulWriter(writer);
21101992 statefulWriter.startNode(rootNodeName, null);
21111993 return new CustomObjectOutputStream(new CustomObjectOutputStream.StreamCallback() {
21352017 }
21362018
21372019 /**
2138 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using
2139 * XStream.
2020 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
21402021 *
21412022 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
2142 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2143 * String)
2023 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
21442024 * @since 1.0.3
21452025 */
21462026 public ObjectInputStream createObjectInputStream(Reader xmlReader) throws IOException {
21482028 }
21492029
21502030 /**
2151 * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream
2152 * using XStream.
2031 * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream using XStream.
21532032 *
21542033 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
2155 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2156 * String)
2034 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
21572035 * @since 1.3
21582036 */
21592037 public ObjectInputStream createObjectInputStream(InputStream in) throws IOException {
21742052 * Object c = out.readObject();
21752053 * </pre>
21762054 *
2177 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2178 * String)
2055 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
21792056 * @since 1.0.3
21802057 */
21812058 public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader) throws IOException {
21972074 throw new EOFException();
21982075 }
21992076 reader.moveDown();
2200 final Object result = unmarshal(reader, dataHolder);
2077 final Object result = unmarshal(reader, null, dataHolder);
22012078 reader.moveUp();
22022079 return result;
22032080 }
22102087 throw new NotActiveException("not in call to readObject");
22112088 }
22122089
2213 public void registerValidation(ObjectInputValidation validation, int priority)
2214 throws NotActiveException {
2090 public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException {
22152091 throw new NotActiveException("stream inactive");
22162092 }
22172093
22222098 }
22232099
22242100 /**
2225 * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will
2226 * register for all kind of classes and types of the current JDK, but not for any 3rd party
2227 * type. To ensure that all other types are loaded with your class loader, you should call
2228 * this method as early as possible - or consider to provide the class loader directly in
2229 * the constructor.
2101 * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will register for all kind
2102 * of classes and types of the current JDK, but not for any 3rd party type. To ensure that all other types are
2103 * loaded with your class loader, you should call this method as early as possible - or consider to provide the
2104 * class loader directly in the constructor.
22302105 *
22312106 * @since 1.1.1
22322107 */
22422117 public ClassLoader getClassLoader() {
22432118 return classLoaderReference.getReference();
22442119 }
2245
2246 /**
2247 * Retrieve the reference to this instance' ClassLoader. Use this reference for other
2248 * XStream components (like converters) to ensure that they will use a changed ClassLoader
2249 * instance automatically.
2120
2121 /**
2122 * Retrieve the reference to this instance' ClassLoader. Use this reference for other XStream components (like
2123 * converters) to ensure that they will use a changed ClassLoader instance automatically.
22502124 *
22512125 * @return the reference
22522126 * @since 1.4.5
22562130 }
22572131
22582132 /**
2259 * Prevents a field from being serialized. To omit a field you must always provide the
2260 * declaring type and not necessarily the type that is converted.
2133 * Prevents a field from being serialized. To omit a field you must always provide the declaring type and not
2134 * necessarily the type that is converted.
22612135 *
22622136 * @since 1.1.3
22632137 * @throws InitializationException if no {@link ElementIgnoringMapper} is available
22702144 }
22712145 elementIgnoringMapper.omitField(definedIn, fieldName);
22722146 }
2273
2147
22742148 /**
22752149 * Ignore all unknown elements.
22762150 *
23132187 */
23142188 public void processAnnotations(final Class[] types) {
23152189 if (annotationConfiguration == null) {
2316 throw new com.thoughtworks.xstream.InitializationException("No "
2317 + ANNOTATION_MAPPER_TYPE
2318 + " available");
2190 throw new com.thoughtworks.xstream.InitializationException("No " + ANNOTATION_MAPPER_TYPE + " available");
23192191 }
23202192 annotationConfiguration.processAnnotations(types);
23212193 }
23222194
23232195 /**
2324 * Process the annotations of the given type and configure the XStream. A call of this
2325 * method will automatically turn the auto-detection mode for annotations off.
2196 * Process the annotations of the given type and configure the XStream. A call of this method will automatically
2197 * turn the auto-detection mode for annotations off.
23262198 *
23272199 * @param type the type with XStream annotations
23282200 * @since 1.3
23322204 }
23332205
23342206 /**
2335 * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies
2336 * that the XStream is configured while it is processing the XML steams. This is a potential
2337 * concurrency problem. Also is it technically not possible to detect all class aliases at
2338 * deserialization. You have been warned!
2207 * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies that the XStream is
2208 * configured while it is processing the XML steams. This is a potential concurrency problem. Also is it technically
2209 * not possible to detect all class aliases at deserialization. You have been warned!
23392210 *
23402211 * @param mode <code>true</code> if annotations are auto-detected
23412212 * @since 1.3
23452216 annotationConfiguration.autodetectAnnotations(mode);
23462217 }
23472218 }
2348
2219
23492220 /**
23502221 * Add a new security permission.
2351 *
23522222 * <p>
23532223 * Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or
23542224 * {@link AnyTypePermission} will implicitly wipe any existing permission.
23592229 */
23602230 public void addPermission(TypePermission permission) {
23612231 if (securityMapper != null) {
2362 securityInitialized = true;
2232 securityInitialized |= permission.equals(NoTypePermission.NONE) || permission.equals(AnyTypePermission.ANY);
23632233 securityMapper.addPermission(permission);
23642234 }
23652235 }
2366
2236
23672237 /**
23682238 * Add security permission for explicit types by name.
23692239 *
23732243 public void allowTypes(String[] names) {
23742244 addPermission(new ExplicitTypePermission(names));
23752245 }
2376
2246
23772247 /**
23782248 * Add security permission for explicit types.
23792249 *
23832253 public void allowTypes(Class[] types) {
23842254 addPermission(new ExplicitTypePermission(types));
23852255 }
2386
2256
23872257 /**
23882258 * Add security permission for a type hierarchy.
23892259 *
23932263 public void allowTypeHierarchy(Class type) {
23942264 addPermission(new TypeHierarchyPermission(type));
23952265 }
2396
2266
23972267 /**
23982268 * Add security permission for types matching one of the specified regular expressions.
23992269 *
24032273 public void allowTypesByRegExp(String[] regexps) {
24042274 addPermission(new RegExpTypePermission(regexps));
24052275 }
2406
2276
24072277 /**
24082278 * Add security permission for types matching one of the specified regular expressions.
24092279 *
24132283 public void allowTypesByRegExp(Pattern[] regexps) {
24142284 addPermission(new RegExpTypePermission(regexps));
24152285 }
2416
2286
24172287 /**
24182288 * Add security permission for types matching one of the specified wildcard patterns.
24192289 * <p>
24212291 * </p>
24222292 * <ul>
24232293 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
2424 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
2425 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
2294 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like
2295 * 'java.lang.*'</li>
2296 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and
2297 * subpackages like 'java.lang.**'</li>
24262298 * </ul>
24272299 *
24282300 * @param patterns the patterns to allow type names
24312303 public void allowTypesByWildcard(String[] patterns) {
24322304 addPermission(new WildcardTypePermission(patterns));
24332305 }
2434
2306
24352307 /**
24362308 * Add security permission denying another one.
24372309 *
24412313 public void denyPermission(TypePermission permission) {
24422314 addPermission(new NoPermission(permission));
24432315 }
2444
2316
24452317 /**
24462318 * Add security permission forbidding explicit types by name.
24472319 *
24512323 public void denyTypes(String[] names) {
24522324 denyPermission(new ExplicitTypePermission(names));
24532325 }
2454
2326
24552327 /**
24562328 * Add security permission forbidding explicit types.
24572329 *
24612333 public void denyTypes(Class[] types) {
24622334 denyPermission(new ExplicitTypePermission(types));
24632335 }
2464
2336
24652337 /**
24662338 * Add security permission forbidding a type hierarchy.
24672339 *
24712343 public void denyTypeHierarchy(Class type) {
24722344 denyPermission(new TypeHierarchyPermission(type));
24732345 }
2474
2346
24752347 /**
24762348 * Add security permission forbidding types matching one of the specified regular expressions.
24772349 *
24812353 public void denyTypesByRegExp(String[] regexps) {
24822354 denyPermission(new RegExpTypePermission(regexps));
24832355 }
2484
2356
24852357 /**
24862358 * Add security permission forbidding types matching one of the specified regular expressions.
24872359 *
24912363 public void denyTypesByRegExp(Pattern[] regexps) {
24922364 denyPermission(new RegExpTypePermission(regexps));
24932365 }
2494
2366
24952367 /**
24962368 * Add security permission forbidding types matching one of the specified wildcard patterns.
24972369 * <p>
24992371 * </p>
25002372 * <ul>
25012373 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
2502 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
2503 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
2374 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like
2375 * 'java.lang.*'</li>
2376 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and
2377 * subpackages like 'java.lang.**'</li>
25042378 * </ul>
25052379 *
25062380 * @param patterns the patterns to forbid names
25162390 }
25172391
25182392 /**
2519 * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException}
2520 * instead
2393 * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException} instead
25212394 */
25222395 public static class InitializationException extends XStreamException {
25232396 /**
25312404
25322405 /**
25332406 * @deprecated As of 1.3, use
2534 * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)}
2535 * instead
2407 * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)} instead
25362408 */
25372409 public InitializationException(String message) {
25382410 super(message);
25392411 }
25402412 }
2541
2542 private class InternalBlackList implements Converter {
2543
2544 public boolean canConvert(final Class type) {
2545 return (type == void.class || type == Void.class)
2546 || (!securityInitialized
2547 && type != null
2548 && (type.getName().equals("java.beans.EventHandler")
2549 || type.getName().endsWith("$LazyIterator")
2550 || type.getName().startsWith("javax.crypto.")));
2551 }
2552
2553 public void marshal(final Object source, final HierarchicalStreamWriter writer,
2554 final MarshallingContext context) {
2555 throw new ConversionException("Security alert. Marshalling rejected.");
2556 }
2557
2558 public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
2559 throw new ConversionException("Security alert. Unmarshalling rejected.");
2560 }
2561 }
25622413 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4343 */
4444 public class PropertiesConverter implements Converter {
4545
46 private final static Field defaultsField = Fields.locate(Properties.class, Properties.class, false);
4746 private final boolean sort;
4847
4948 public PropertiesConverter() {
6867 writer.addAttribute("value", entry.getValue().toString());
6968 writer.endNode();
7069 }
71 if (defaultsField != null) {
72 Properties defaults = (Properties)Fields.read(defaultsField, properties);
70 if (Reflections.defaultsField != null) {
71 Properties defaults = (Properties)Fields.read(Reflections.defaultsField, properties);
7372 if (defaults != null) {
7473 writer.startNode("defaults");
7574 marshal(defaults, writer, context);
101100 }
102101 }
103102
103 private static class Reflections {
104 private final static Field defaultsField = Fields.locate(Properties.class, Properties.class, false);
105 }
104106 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4646 }
4747
4848 private final static Comparator NULL_MARKER = new NullComparator();
49 private final static Field comparatorField = Fields.locate(TreeMap.class, Comparator.class, false);
5049
5150 public TreeMapConverter(Mapper mapper) {
5251 super(mapper, TreeMap.class);
7069 }
7170
7271 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
73 TreeMap result = comparatorField != null ? new TreeMap() : null;
72 TreeMap result = Reflections.comparatorField != null ? new TreeMap() : null;
7473 final Comparator comparator = unmarshalComparator(reader, context, result);
7574 if (result == null) {
7675 result = comparator == null || comparator == NULL_MARKER ? new TreeMap() : new TreeMap(comparator);
115114 populateMap(reader, context, result, sortedMap);
116115 try {
117116 if (JVM.hasOptimizedTreeMapPutAll()) {
118 if (comparator != null && comparatorField != null) {
119 comparatorField.set(result, comparator);
117 if (comparator != null && Reflections.comparatorField != null) {
118 Reflections.comparatorField.set(result, comparator);
120119 }
121120 result.putAll(sortedMap); // internal optimization will not call comparator
122 } else if (comparatorField != null) {
123 comparatorField.set(result, sortedMap.comparator());
121 } else if (Reflections.comparatorField != null) {
122 Reflections.comparatorField.set(result, sortedMap.comparator());
124123 result.putAll(sortedMap); // "sort" by index
125 comparatorField.set(result, comparator);
124 Reflections.comparatorField.set(result, comparator);
126125 } else {
127126 result.putAll(sortedMap); // will use comparator for already sorted map
128127 }
130129 throw new ObjectAccessException("Cannot set comparator of TreeMap", e);
131130 }
132131 }
132
133 private static class Reflections {
134 private final static Field comparatorField = Fields.locate(TreeMap.class, Comparator.class, false);
135 }
133136 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014, 2016, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014, 2016, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4040 */
4141 public class TreeSetConverter extends CollectionConverter {
4242 private transient TreeMapConverter treeMapConverter;
43 private final static Field sortedMapField;
44 private final static Object constantValue;
45 static {
46 Object value = null;
47 sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, SortedMap.class, false) : null;
48 if (sortedMapField != null) {
49 TreeSet set = new TreeSet();
50 set.add("1");
51 set.add("2");
52
53 Map backingMap = null;
54 try {
55 backingMap = (Map)sortedMapField.get(set);
56 } catch (final IllegalAccessException e) {
57 // give up;
58 }
59 if (backingMap != null) {
60 Object[] values = backingMap.values().toArray();
61 if (values[0] == values[1]) {
62 value = values[0];
63 }
64 }
65 } else {
66 Field valueField = Fields.locate(TreeSet.class, Object.class, true);
67 if (valueField != null) {
68 try {
69 value = valueField.get(null);
70 } catch (final IllegalAccessException e) {
71 // give up;
72 }
73 }
74 }
75 constantValue = value;
76 }
7743
7844 public TreeSetConverter(Mapper mapper) {
7945 super(mapper, TreeSet.class);
9258 Comparator unmarshalledComparator = treeMapConverter.unmarshalComparator(reader, context, null);
9359 boolean inFirstElement = unmarshalledComparator instanceof Mapper.Null;
9460 Comparator comparator = inFirstElement ? null : unmarshalledComparator;
95 if (sortedMapField != null) {
61 if (Reflections.sortedMapField != null) {
9662 TreeSet possibleResult = comparator == null ? new TreeSet() : new TreeSet(comparator);
9763 Object backingMap = null;
9864 try {
99 backingMap = sortedMapField.get(possibleResult);
65 backingMap = Reflections.sortedMapField.get(possibleResult);
10066 } catch (IllegalAccessException e) {
10167 throw new ObjectAccessException("Cannot get backing map of TreeSet", e);
10268 }
134100 UnmarshallingContext context, Map map, final Map target) {
135101 populateCollection(reader, context, new AbstractList() {
136102 public boolean add(Object object) {
137 return target.put(object, constantValue != null ? constantValue : object) != null;
103 return target
104 .put(object, Reflections.constantValue != null
105 ? Reflections.constantValue
106 : object) != null;
138107 }
139108
140109 public Object get(int location) {
155124 };
156125 return this;
157126 }
127
128 private static class Reflections {
129
130 private final static Field sortedMapField;
131 private final static Object constantValue;
132 static {
133 Object value = null;
134 sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, SortedMap.class, false) : null;
135 if (sortedMapField != null) {
136 TreeSet set = new TreeSet();
137 set.add("1");
138 set.add("2");
139
140 Map backingMap = null;
141 try {
142 backingMap = (Map)sortedMapField.get(set);
143 } catch (final IllegalAccessException e) {
144 // give up;
145 }
146 if (backingMap != null) {
147 Object[] values = backingMap.values().toArray();
148 if (values[0] == values[1]) {
149 value = values[0];
150 }
151 }
152 } else {
153 Field valueField = Fields.locate(TreeSet.class, Object.class, true);
154 if (valueField != null) {
155 try {
156 value = valueField.get(null);
157 } catch (final IllegalAccessException e) {
158 // give up;
159 }
160 }
161 }
162 constantValue = value;
163 }
164 }
158165 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3636 */
3737 public class EnumMapConverter extends MapConverter {
3838
39 private final static Field typeField = Fields.locate(EnumMap.class, Class.class, false);
40
4139 public EnumMapConverter(Mapper mapper) {
4240 super(mapper);
4341 }
4442
4543 public boolean canConvert(Class type) {
46 return typeField != null && type == EnumMap.class;
44 return type == EnumMap.class && Reflections.typeField != null;
4745 }
4846
4947 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
50 Class type = (Class) Fields.read(typeField, source);
48 Class type = (Class) Fields.read(Reflections.typeField, source);
5149 String attributeName = mapper().aliasForSystemAttribute("enum-type");
5250 if (attributeName != null) {
5351 writer.addAttribute(attributeName, mapper().serializedClass(type));
6664 populateMap(reader, context, map);
6765 return map;
6866 }
67
68 private static class Reflections {
69 private final static Field typeField = Fields.locate(EnumMap.class, Class.class, false);
70 }
6971 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3838 */
3939 public class EnumSetConverter implements Converter {
4040
41 private final static Field typeField = Fields.locate(EnumSet.class, Class.class, false);
4241 private final Mapper mapper;
4342
4443 public EnumSetConverter(Mapper mapper) {
4645 }
4746
4847 public boolean canConvert(Class type) {
49 return typeField != null && type != null && EnumSet.class.isAssignableFrom(type);
48 return type != null && EnumSet.class.isAssignableFrom(type) && Reflections.typeField != null;
5049 }
5150
5251 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
5352 EnumSet set = (EnumSet) source;
54 Class enumTypeForSet = (Class) Fields.read(typeField, set);
53 Class enumTypeForSet = (Class) Fields.read(Reflections.typeField, set);
5554 String attributeName = mapper.aliasForSystemAttribute("enum-type");
5655 if (attributeName != null) {
5756 writer.addAttribute(attributeName, mapper.serializedClass(enumTypeForSet));
9291 return set;
9392 }
9493
94 private static class Reflections {
95 private final static Field typeField = Fields.locate(EnumSet.class, Class.class, false);
96 }
9597 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2013, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2013, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3838
3939 private ClassLoaderReference classLoaderReference;
4040 private Mapper mapper;
41 private static final Field HANDLER = Fields.locate(Proxy.class, InvocationHandler.class, false);
42 private static final InvocationHandler DUMMY = new InvocationHandler() {
43 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
44 return null;
45 }
46 };
4741
4842 /**
4943 * @deprecated As of 1.4.5 use {@link #DynamicProxyConverter(Mapper, ClassLoaderReference)}
120114 Class[] interfacesAsArray = new Class[interfaces.size()];
121115 interfaces.toArray(interfacesAsArray);
122116 Object proxy = null;
123 if (HANDLER != null) { // we will not be able to resolve references to the proxy
124 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, DUMMY);
117 if (Reflections.HANDLER != null) { // we will not be able to resolve references to the proxy
118 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, Reflections.DUMMY);
125119 }
126120 handler = (InvocationHandler) context.convertAnother(proxy, handlerType);
127121 reader.moveUp();
128 if (HANDLER != null) {
129 Fields.write(HANDLER, proxy, handler);
122 if (Reflections.HANDLER != null) {
123 Fields.write(Reflections.HANDLER, proxy, handler);
130124 } else {
131125 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, handler);
132126 }
133127 return proxy;
134128 }
129
130 private static class Reflections {
131
132 private static final Field HANDLER = Fields.locate(Proxy.class, InvocationHandler.class, false);
133 private static final InvocationHandler DUMMY = new InvocationHandler() {
134 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
135 return null;
136 }
137 };
138 }
135139 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2016 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2016, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4141 }
4242
4343 /**
44 * Construct a BeanProvider with a comparator to sort the bean properties by name in the
45 * dictionary.
44 * Construct a BeanProvider with a comparator to sort the bean properties by name in the dictionary.
4645 *
4746 * @param propertyNameComparator the comparator
4847 */
6261
6362 public Object newInstance(Class type) {
6463 ErrorWritingException ex = null;
65 try {
66 return type.newInstance();
67 } catch (InstantiationException e) {
68 ex = new ConversionException("Cannot construct type", e);
69 } catch (IllegalAccessException e) {
70 ex = new ObjectAccessException("Cannot construct type", e);
71 } catch (SecurityException e) {
72 ex = new ObjectAccessException("Cannot construct type", e);
73 } catch (ExceptionInInitializerError e) {
74 ex = new ConversionException("Cannot construct type", e);
64 if (type == void.class || type == Void.class) {
65 ex = new ConversionException("Security alert: Marshalling rejected");
66 } else {
67 try {
68 return type.newInstance();
69 } catch (InstantiationException e) {
70 ex = new ConversionException("Cannot construct type", e);
71 } catch (IllegalAccessException e) {
72 ex = new ObjectAccessException("Cannot construct type", e);
73 } catch (SecurityException e) {
74 ex = new ObjectAccessException("Cannot construct type", e);
75 } catch (ExceptionInInitializerError e) {
76 ex = new ConversionException("Cannot construct type", e);
77 }
7578 }
7679 ex.add("construction-type", type.getName());
7780 throw ex;
7982
8083 public void visitSerializableProperties(Object object, JavaBeanProvider.Visitor visitor) {
8184 PropertyDescriptor[] propertyDescriptors = getSerializableProperties(object);
82 for (int i = 0; i < propertyDescriptors.length; i++ ) {
85 for (int i = 0; i < propertyDescriptors.length; i++) {
8386 ErrorWritingException ex = null;
8487 PropertyDescriptor property = propertyDescriptors[i];
8588 try {
135138 */
136139 public boolean canInstantiate(Class type) {
137140 try {
138 return type != null && newInstance(type) != null;
141 return type != null && newInstance(type) != null;
139142 } catch (final ErrorWritingException e) {
140143 return false;
141144 }
148151 * @deprecated As of 1.4.6 use {@link #newInstance(Class)} or {@link #canInstantiate(Class)} directly.
149152 */
150153 protected Constructor getDefaultConstrutor(Class type) {
151
154
152155 Constructor[] constructors = type.getConstructors();
153 for (int i = 0; i < constructors.length; i++ ) {
156 for (int i = 0; i < constructors.length; i++) {
154157 Constructor c = constructors[i];
155158 if (c.getParameterTypes().length == 0 && Modifier.isPublic(c.getModifiers()))
156159 return c;
185188 /**
186189 * @deprecated As of 1.4 use {@link JavaBeanProvider.Visitor}
187190 */
188 public interface Visitor extends JavaBeanProvider.Visitor {
189 }
191 public interface Visitor extends JavaBeanProvider.Visitor {}
190192 }
00 /*
1 * Copyright (C) 2007, 2013, 2016 XStream Committers.
1 * Copyright (C) 2007, 2013, 2016, 2020 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1818 import java.lang.reflect.Method;
1919 import java.lang.reflect.Modifier;
2020 import java.text.AttributedCharacterIterator;
21 import java.util.Collections;
2122 import java.util.HashMap;
2223 import java.util.Iterator;
2324 import java.util.Map;
3334 public class AbstractAttributedCharacterIteratorAttributeConverter extends
3435 AbstractSingleValueConverter {
3536
36 private static final Map instanceMaps = new HashMap();
37 private static final Method getName;
38 static {
39 Method method = null;
40 try {
41 method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod(
42 "getName", (Class[])null);
43 if (!method.isAccessible()) {
44 method.setAccessible(true);
45 }
46 } catch (SecurityException e) {
47 // ignore for now
48 } catch (NoSuchMethodException e) {
49 // ignore for now
50 }
51 getName = method;
52 }
37 private static final Map instanceMaps = Collections.synchronizedMap(new HashMap());
5338
5439 private final Class type;
55 private transient Map attributeMap;
5640
5741 public AbstractAttributedCharacterIteratorAttributeConverter(final Class type) {
5842 super();
6145 + " is not a " + AttributedCharacterIterator.Attribute.class.getName());
6246 }
6347 this.type = type;
64 readResolve();
6548 }
6649
6750 public boolean canConvert(final Class type) {
68 return type == this.type && !attributeMap.isEmpty();
51 return type == this.type && !getAttributeMap().isEmpty();
6952 }
7053
7154 public String toString(final Object source) {
7457
7558 private String getName(AttributedCharacterIterator.Attribute attribute) {
7659 Exception ex = null;
77 if (getName != null) {
60 if (Reflections.getName != null) {
7861 try {
79 return (String)getName.invoke(attribute, (Object[])null);
62 return (String)Reflections.getName.invoke(attribute, (Object[])null);
8063 } catch (IllegalAccessException e) {
8164 ex = e;
8265 } catch (InvocationTargetException e) {
9477 }
9578
9679 public Object fromString(final String str) {
97 if (attributeMap.containsKey(str)) {
98 return attributeMap.get(str);
80 Object attr = getAttributeMap().get(str);
81 if (attr != null) {
82 return attr;
9983 }
10084 ConversionException exception = new ConversionException("Cannot find attribute");
10185 exception.add("attribute-type", type.getName());
10387 throw exception;
10488 }
10589
106 private Object readResolve() {
107 attributeMap = (Map)instanceMaps.get(type.getName());
90 private Map getAttributeMap() {
91 Map attributeMap = (Map)instanceMaps.get(type.getName());
10892 if (attributeMap == null) {
109 attributeMap = new HashMap();
110 Field instanceMap = Fields.locate(type, Map.class, true);
111 if (instanceMap != null) {
112 try {
113 Map map = (Map)Fields.read(instanceMap, null);
114 if (map != null) {
115 boolean valid = true;
116 for (Iterator iter = map.entrySet().iterator(); valid && iter.hasNext(); ) {
117 Map.Entry entry = (Map.Entry)iter.next();
118 valid = entry.getKey().getClass() == String.class && entry.getValue().getClass() == type;
119 }
120 if (valid) {
121 attributeMap.putAll(map);
122 }
123 }
124 } catch (ObjectAccessException e) {
125 }
126 }
127 if (attributeMap.isEmpty()) {
128 try {
129 Field[] fields = type.getDeclaredFields();
130 for(int i = 0; i < fields.length; ++i) {
131 if(fields[i].getType() == type == Modifier.isStatic(fields[i].getModifiers())) {
132 AttributedCharacterIterator.Attribute attribute =
133 (AttributedCharacterIterator.Attribute)Fields.read(fields[i], null);
134 attributeMap.put(toString(attribute), attribute);
135 }
136 }
137 } catch (SecurityException e) {
138 attributeMap.clear();
139 } catch (ObjectAccessException e) {
140 attributeMap.clear();
141 } catch (NoClassDefFoundError e) {
142 attributeMap.clear();
143 }
144 }
93 attributeMap = buildAttributeMap();
14594 instanceMaps.put(type.getName(), attributeMap);
14695 }
147 return this;
96 return attributeMap;
14897 }
14998
99 private Map buildAttributeMap() {
100 final Map attributeMap = new HashMap();
101 final Field instanceMap = Fields.locate(type, Map.class, true);
102 if (instanceMap != null) {
103 try {
104 Map map = (Map)Fields.read(instanceMap, null);
105 if (map != null) {
106 boolean valid = true;
107 for (Iterator iter = map.entrySet().iterator(); valid && iter.hasNext(); ) {
108 Map.Entry entry = (Map.Entry)iter.next();
109 valid = entry.getKey().getClass() == String.class && entry.getValue().getClass() == type;
110 }
111 if (valid) {
112 attributeMap.putAll(map);
113 }
114 }
115 } catch (ObjectAccessException e) {
116 }
117 }
118 if (attributeMap.isEmpty()) {
119 try {
120 Field[] fields = type.getDeclaredFields();
121 for(int i = 0; i < fields.length; ++i) {
122 if(fields[i].getType() == type == Modifier.isStatic(fields[i].getModifiers())) {
123 AttributedCharacterIterator.Attribute attribute =
124 (AttributedCharacterIterator.Attribute)Fields.read(fields[i], null);
125 attributeMap.put(toString(attribute), attribute);
126 }
127 }
128 } catch (SecurityException e) {
129 attributeMap.clear();
130 } catch (ObjectAccessException e) {
131 attributeMap.clear();
132 } catch (NoClassDefFoundError e) {
133 attributeMap.clear();
134 }
135 }
136 return attributeMap;
137 }
138
139 private static class Reflections {
140
141 private static final Method getName;
142 static {
143 Method method = null;
144 try {
145 method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod(
146 "getName", (Class[])null);
147 if (!method.isAccessible()) {
148 method.setAccessible(true);
149 }
150 } catch (SecurityException e) {
151 // ignore for now
152 } catch (NoSuchMethodException e) {
153 // ignore for now
154 }
155 getName = method;
156 }
157 }
150158 }
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2016, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2016, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
1010 */
1111 package com.thoughtworks.xstream.converters.reflection;
1212
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.ErrorWritingException;
1315 import com.thoughtworks.xstream.core.JVM;
1416 import com.thoughtworks.xstream.core.util.Fields;
1517
2931 import java.util.Map;
3032 import java.util.WeakHashMap;
3133
34
3235 /**
33 * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects
34 * that can be constructed are limited.
36 * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects that
37 * can be constructed are limited.
3538 * <p>
36 * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default constructors
37 * and any class that implements java.io.Serializable.
39 * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default
40 * constructors and any class that implements java.io.Serializable.
3841 * </p>
3942 * <p>
40 * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default constructors.
41 * Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates the object.
43 * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default
44 * constructors. Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates
45 * the object.
4246 * </p>
47 *
4348 * @author Joe Walnes
4449 */
4550 public class PureJavaReflectionProvider implements ReflectionProvider {
5762 }
5863
5964 public Object newInstance(Class type) {
60 ObjectAccessException oaex = null;
61 try {
62 Constructor[] constructors = type.getDeclaredConstructors();
63 for (int i = 0; i < constructors.length; i++) {
64 final Constructor constructor = constructors[i];
65 if (constructor.getParameterTypes().length == 0) {
66 if (!constructor.isAccessible()) {
67 constructor.setAccessible(true);
65 ErrorWritingException ex = null;
66 if (type == void.class || type == Void.class) {
67 ex = new ConversionException("Security alert: Marshalling rejected");
68 } else {
69 try {
70 Constructor[] constructors = type.getDeclaredConstructors();
71 for (int i = 0; i < constructors.length; i++) {
72 final Constructor constructor = constructors[i];
73 if (constructor.getParameterTypes().length == 0) {
74 if (!constructor.isAccessible()) {
75 constructor.setAccessible(true);
76 }
77 return constructor.newInstance(new Object[0]);
6878 }
69 return constructor.newInstance(new Object[0]);
70 }
71 }
72 if (Serializable.class.isAssignableFrom(type)) {
73 return instantiateUsingSerialization(type);
74 } else {
75 oaex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor");
76 }
77 } catch (InstantiationException e) {
78 oaex = new ObjectAccessException("Cannot construct type", e);
79 } catch (IllegalAccessException e) {
80 oaex = new ObjectAccessException("Cannot construct type", e);
81 } catch (InvocationTargetException e) {
82 if (e.getTargetException() instanceof RuntimeException) {
83 throw (RuntimeException)e.getTargetException();
84 } else if (e.getTargetException() instanceof Error) {
85 throw (Error)e.getTargetException();
86 } else {
87 oaex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException());
88 }
89 }
90 oaex.add("construction-type", type.getName());
91 throw oaex;
79 }
80 if (Serializable.class.isAssignableFrom(type)) {
81 return instantiateUsingSerialization(type);
82 } else {
83 ex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor");
84 }
85 } catch (InstantiationException e) {
86 ex = new ObjectAccessException("Cannot construct type", e);
87 } catch (IllegalAccessException e) {
88 ex = new ObjectAccessException("Cannot construct type", e);
89 } catch (InvocationTargetException e) {
90 if (e.getTargetException() instanceof RuntimeException) {
91 throw (RuntimeException)e.getTargetException();
92 } else if (e.getTargetException() instanceof Error) {
93 throw (Error)e.getTargetException();
94 } else {
95 ex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException());
96 }
97 }
98 }
99 ex.add("construction-type", type.getName());
100 throw ex;
92101 }
93102
94103 private Object instantiateUsingSerialization(final Class type) {
95104 ObjectAccessException oaex = null;
96105 try {
97106 synchronized (serializedDataCache) {
98 byte[] data = (byte[]) serializedDataCache.get(type);
99 if (data == null) {
107 byte[] data = (byte[])serializedDataCache.get(type);
108 if (data == null) {
100109 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
101110 DataOutputStream stream = new DataOutputStream(bytes);
102111 stream.writeShort(ObjectStreamConstants.STREAM_MAGIC);
105114 stream.writeByte(ObjectStreamConstants.TC_CLASSDESC);
106115 stream.writeUTF(type.getName());
107116 stream.writeLong(ObjectStreamClass.lookup(type).getSerialVersionUID());
108 stream.writeByte(2); // classDescFlags (2 = Serializable)
117 stream.writeByte(2); // classDescFlags (2 = Serializable)
109118 stream.writeShort(0); // field count
110119 stream.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
111120 stream.writeByte(ObjectStreamConstants.TC_NULL);
112121 data = bytes.toByteArray();
113122 serializedDataCache.put(type, data);
114123 }
115
124
116125 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)) {
117 protected Class resolveClass(ObjectStreamClass desc)
118 throws IOException, ClassNotFoundException {
126 protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
119127 return Class.forName(desc.getName(), false, type.getClassLoader());
120128 }
121129 };
132140
133141 public void visitSerializableFields(Object object, ReflectionProvider.Visitor visitor) {
134142 for (Iterator iterator = fieldDictionary.fieldsFor(object.getClass()); iterator.hasNext();) {
135 Field field = (Field) iterator.next();
143 Field field = (Field)iterator.next();
136144 if (!fieldModifiersSupported(field)) {
137145 continue;
138146 }
173181 }
174182 } else {
175183 throw new ObjectAccessException("Invalid final field "
176 + field.getDeclaringClass().getName() + "." + field.getName());
184 + field.getDeclaringClass().getName()
185 + "."
186 + field.getName());
177187 }
178188 }
179189 }
183193 }
184194
185195 public Field getFieldOrNull(Class definedIn, String fieldName) {
186 return fieldDictionary.fieldOrNull(definedIn, fieldName, null);
196 return fieldDictionary.fieldOrNull(definedIn, fieldName, null);
187197 }
188198
189199 public void setFieldDictionary(FieldDictionary dictionary) {
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * Created on 08. January 2014 by Joerg Schaible, factored out from SunUnsafeReflectionProvider
7878 }
7979 ErrorWritingException ex = null;
8080 if (type == void.class || type == Void.class) {
81 ex = new ConversionException("Type void cannot have an instance");
81 ex = new ConversionException("Security alert: Marshalling rejected");
8282 } else {
8383 try {
8484 return unsafe.allocateInstance(type);
00 /*
1 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream Committers.
1 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2019 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1212 import com.thoughtworks.xstream.converters.ConversionException;
1313 import com.thoughtworks.xstream.converters.Converter;
1414 import com.thoughtworks.xstream.converters.ConverterLookup;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
1615 import com.thoughtworks.xstream.core.util.ObjectIdDictionary;
1716 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
1817 import com.thoughtworks.xstream.io.path.Path;
3029 * @author Mauro Talevi
3130 * @since 1.2
3231 */
33 public abstract class AbstractReferenceMarshaller extends TreeMarshaller implements MarshallingContext {
32 public abstract class AbstractReferenceMarshaller extends TreeMarshaller {
3433
3534 private ObjectIdDictionary references = new ObjectIdDictionary();
3635 private ObjectIdDictionary implicitElements = new ObjectIdDictionary();
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2016, 2017 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2016, 2017, 2019 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
8787 final ConversionException exception = new ConversionException(errors.isEmpty()
8888 ? "No converter specified"
8989 : "No converter available");
90 exception.add("type", type.getName());
90 exception.add("type", type != null ? type.getName() : "null");
9191 iterator = errors.entrySet().iterator();
9292 while (iterator.hasNext()) {
9393 final Map.Entry entry = (Map.Entry)iterator.next();
00 /*
1 * Copyright (C) 2007, 2008, 2010 XStream Committers.
1 * Copyright (C) 2007, 2008, 2010, 2020 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
6464
6565 private Map getHeader(final PushbackInputStream[] in) throws IOException {
6666 final Map header = new HashMap();
67 header.put(KEY_ENCODING, "utf-8");
67 header.put(KEY_ENCODING, "UTF-8");
6868 header.put(KEY_VERSION, "1.0");
6969
7070 int state = STATE_BOM;
00 /*
1 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013 XStream Committers.
1 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013, 2018 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
5151 * Construct a JettisonMappedXmlDriver.
5252 */
5353 public JettisonMappedXmlDriver() {
54 this(new Configuration());
54 this(null);
5555 }
5656
5757 /**
7272 * @param useSerializeAsArray flag to use XStream's hints for collections and arrays
7373 * @since 1.4
7474 */
75 public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) {
75 public JettisonMappedXmlDriver(Configuration config, final boolean useSerializeAsArray) {
76 config = config == null ? new Configuration() : config;
7677 mof = new MappedXMLOutputFactory(config);
7778 mif = new MappedXMLInputFactory(config);
7879 convention = new MappedNamespaceConvention(config);
00 /*
1 * Copyright (c) 2008, 2009, 2010, 2011 XStream Committers.
1 * Copyright (c) 2008, 2009, 2010, 2011, 2018 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
55 * style license a copy of which has been included with this distribution in
66 * the LICENSE.txt file.
7 *
7 *
88 * Created on 17.04.2008 by Joerg Schaible.
99 */
1010 package com.thoughtworks.xstream.io.json;
1111
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Map;
16
17 import javax.xml.namespace.QName;
18 import javax.xml.stream.XMLStreamException;
19 import javax.xml.stream.XMLStreamWriter;
20
21 import org.codehaus.jettison.AbstractXMLStreamWriter;
22 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
23
24 import com.thoughtworks.xstream.core.JVM;
1225 import com.thoughtworks.xstream.io.naming.NameCoder;
1326 import com.thoughtworks.xstream.io.xml.QNameMap;
1427 import com.thoughtworks.xstream.io.xml.StaxWriter;
1528 import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
1629
17 import org.codehaus.jettison.AbstractXMLStreamWriter;
18 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
19
20 import javax.xml.namespace.QName;
21 import javax.xml.stream.XMLStreamException;
22 import javax.xml.stream.XMLStreamWriter;
23
24 import java.util.Collection;
25 import java.util.Map;
26
2730
2831 /**
2932 * A specialized {@link StaxWriter} that makes usage of internal functionality of Jettison.
30 *
33 *
3134 * @author J&ouml;rg Schaible
3235 * @since 1.3.1
3336 */
3437 public class JettisonStaxWriter extends StaxWriter {
3538
3639 private final MappedNamespaceConvention convention;
40 private final List stack = new ArrayList();
3741
3842 /**
3943 * @since 1.4
4044 */
4145 public JettisonStaxWriter(
42 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
43 boolean namespaceRepairingMode, NameCoder nameCoder,
44 MappedNamespaceConvention convention) throws XMLStreamException {
46 final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument,
47 final boolean namespaceRepairingMode, final NameCoder nameCoder, final MappedNamespaceConvention convention)
48 throws XMLStreamException {
4549 super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, nameCoder);
4650 this.convention = convention;
4751 }
5256 * instead
5357 */
5458 public JettisonStaxWriter(
55 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
56 boolean namespaceRepairingMode, XmlFriendlyReplacer replacer,
57 MappedNamespaceConvention convention) throws XMLStreamException {
58 this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder) replacer, convention);
59 final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument,
60 final boolean namespaceRepairingMode, final XmlFriendlyReplacer replacer,
61 final MappedNamespaceConvention convention)
62 throws XMLStreamException {
63 this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder)replacer, convention);
5964 }
6065
6166 public JettisonStaxWriter(
62 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
63 boolean namespaceRepairingMode, MappedNamespaceConvention convention)
64 throws XMLStreamException {
67 final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument,
68 final boolean namespaceRepairingMode, final MappedNamespaceConvention convention)
69 throws XMLStreamException {
6570 super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode);
6671 this.convention = convention;
6772 }
6873
6974 public JettisonStaxWriter(
70 QNameMap qnameMap, XMLStreamWriter out, MappedNamespaceConvention convention)
71 throws XMLStreamException {
75 final QNameMap qnameMap, final XMLStreamWriter out, final MappedNamespaceConvention convention)
76 throws XMLStreamException {
7277 super(qnameMap, out);
7378 this.convention = convention;
7479 }
7782 * @since 1.4
7883 */
7984 public JettisonStaxWriter(
80 QNameMap qnameMap, XMLStreamWriter out, NameCoder nameCoder, MappedNamespaceConvention convention)
81 throws XMLStreamException {
85 final QNameMap qnameMap, final XMLStreamWriter out, final NameCoder nameCoder,
86 final MappedNamespaceConvention convention)
87 throws XMLStreamException {
8288 super(qnameMap, out, nameCoder);
8389 this.convention = convention;
8490 }
8591
86 public void startNode(String name, Class clazz) {
87 XMLStreamWriter out = getXMLStreamWriter();
92 public void startNode(final String name, final Class clazz) {
93 final XMLStreamWriter out = getXMLStreamWriter();
94 String key = "";
8895 if (clazz != null && out instanceof AbstractXMLStreamWriter) {
89 if (Collection.class.isAssignableFrom(clazz)
90 || Map.class.isAssignableFrom(clazz)
91 || clazz.isArray()) {
92 QName qname = getQNameMap().getQName(encodeNode(name));
93 String prefix = qname.getPrefix();
94 String uri = qname.getNamespaceURI();
95 String key = convention.createKey(prefix, uri, qname.getLocalPart());
96 if (!((AbstractXMLStreamWriter)out).getSerializedAsArrays().contains(key)) {
97 // Typo is in the API of Jettison ...
98 ((AbstractXMLStreamWriter)out).seriliazeAsArray(key);
96 if (Collection.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz) || clazz.isArray()) {
97 final QName qname = getQNameMap().getQName(encodeNode(name));
98 final String prefix = qname.getPrefix();
99 final String uri = qname.getNamespaceURI();
100 key = convention.createKey(prefix, uri, qname.getLocalPart());
101
102 if (!JVM.is15()) {
103 final ArrayList serializedAsArrays = ((AbstractXMLStreamWriter)out).getSerializedAsArrays();
104 if (!serializedAsArrays.contains(key)) {
105 serializedAsArrays.add(key);
106 }
107 key = "";
99108 }
100109 }
101110 }
102 startNode(name);
111 stack.add(key);
112 super.startNode(name);
113 }
114
115 public void startNode(final String name) {
116 startNode(name, null);
117 }
118
119 public void endNode() {
120 final String key = (String)stack.remove(stack.size() - 1);
121 if (key.length() == 0) {
122 super.endNode();
123 } else {
124 final XMLStreamWriter out = getXMLStreamWriter();
125 final ArrayList serializedAsArrays = ((AbstractXMLStreamWriter)out).getSerializedAsArrays();
126 serializedAsArrays.add(key);
127 super.endNode();
128 serializedAsArrays.remove(key);
129 }
103130 }
104131 }
6767 } catch (ClassNotFoundException e) {
6868 exception = e;
6969 }
70 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFaqctory instance.", exception);
70 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFactory instance.", exception);
7171 }
7272
7373 /**
8484 } catch (ClassNotFoundException e) {
8585 exception = e;
8686 }
87 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLOutputFaqctory instance.", exception);
87 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLOutputFactory instance.", exception);
8888 }
8989
9090 }
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2018 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
5454
5555 protected int pullNextEvent() {
5656 try {
57 switch(in.next()) {
58 case XMLStreamConstants.START_DOCUMENT:
59 case XMLStreamConstants.START_ELEMENT:
60 return START_NODE;
61 case XMLStreamConstants.END_DOCUMENT:
62 case XMLStreamConstants.END_ELEMENT:
63