Comments (4)
This is no bug, this is by design. A TreeSet/TreeMap may have an own Comparator and the Java API has no official way, to get them, therefore reflection is the only way. So, do as the exception says, run your application with run time option "--add-opens java.base/java.util=ALL-UNNAMED"
from xstream.
This is no bug, this is by design. A TreeSet/TreeMap may have an own Comparator and the Java API has no official way, to get them, therefore reflection is the only way. So, do as the exception says, run your application with run time option "--add-opens java.base/java.util=ALL-UNNAMED"
I known your meaning, but if i change like this (still not use "--add-opens java.base/java.util=ALL-UNNAMED")
public static void main(String[] args) {
var ts = new TreeSet();
//var al = new ArrayList();
//al.add("ABC");
//ts.add(al);
ts.add("");//String is Comparable
var xs = new XStream();
xs.allowTypesByWildcard(new String[]{"**"});
var str = xs.toXML(ts);
System.out.println(str);
var obj = xs.fromXML(str);//TreeMap has the same problem
System.out.println(obj);
}
The problem like this:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.thoughtworks.xstream.converters.collections.TreeSetConverter.unmarshal(TreeSetConverter.java:62)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:74)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:68)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:52)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:136)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1464)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1441)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1321)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1312)
at com.example.webenv174jar.XStreamTest.main(XStreamTest.java:26)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.util.NavigableMap java.util.TreeSet.m accessible: module java.base does not "opens java.util" to unnamed module @11a9e7c8
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:40)
at com.thoughtworks.xstream.converters.collections.TreeSetConverter$Reflections.(TreeSetConverter.java:135)
This problem is also by design?
from xstream.
Yes, because how should XStream know, if a comparator has been set? There's just one way: Look into the private field.
from xstream.
Yes, because how should XStream know, if a comparator has been set? There's just one way: Look into the private field.
So even if not use comparator, also need "--add-opens java.base/java.util=ALL-UNNAMED", it maybe a bit redundant, if catch and handle exception may have a better experience., but i understand, thank you
from xstream.
Related Issues (20)
- XStreamOmitField default value HOT 1
- how to remove the class attribute when serializing Java Bean to xml? HOT 1
- `PrettyPrintWriter` cannot write emoji in XML 1.1 mode HOT 1
- how to parse xml string into class with genericity HOT 3
- How to set byte array not to do conversion?Thanks. HOT 1
- Unmodifiable Lists converter HOT 1
- how both text and sub tags exist HOT 3
- DomReader: slow performance $O(n^2)$ when deserialize on millions of elements to list HOT 3
- B
- Is there any annotations can support both attribute and sub tags HOT 1
- Support Record Classes HOT 1
- com.thoughtworks.xstream.core.util is not exported in OSGI manifest HOT 2
- Avoid SimpleDateFormat
- Maven errors with java 21 HOT 1
- The vulnerabilities database NVD only finds xstream component with VENDOR= xstream_project HOT 1
- When will 1.5 released with hibernate 6 support? HOT 6
- Deserializing large files is slow on low-performance devices HOT 1
- CustomObjectInputStream's readInt throws a cast error if the read data is a Byte. HOT 6
- Alias using serialization proxy pattern ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xstream.