Comments (6)
BTW: Just using a formatter that sorts the members of a class into a different order might cause such problems...
from xstream.
Actually I don't understand the question. This is how Java Serialization works: If you have written a Byte into the object stream, you will have to read a Byte again. It will not miraculously turn into an Integer, just because you do now try to read one. You broke the API contract.
from xstream.
@joehni
Thank you for your feedback. I know about the Stream API contract. But The problem is that if the type read from the stream is bytes, explicit conversion to a reference type integer will result in a cast error.
I think it should be modified as shown in the example, but if I'm not understanding about this feature, please let me know.
return ((int)peekCallback().readFromStream());
return peekCallback().readFromStream().intValue(); // Convert Byte to int (auto-unboxing followed by implicit casting)
from xstream.
Maybe you should also have a look at CustomObjectOutputStream, then you'll see, that the custom implementations of XStream will only write objects, since the representing tag (e.g. "int") in XML does not differentiate between the native and the boxed type, they are represented in the same way. However, if the method readInt() has been called, the (XML) stream must contain an Integer object, that is returned unboxed again.
from xstream.
Maybe you should also have a look at CustomObjectOutputStream, then you'll see, that the custom implementations of XStream will only write objects, since the representing tag (e.g. "int") in XML does not differentiate between the native and the boxed type, they are represented in the same way. However, if the method readInt() has been called, the (XML) stream must contain an Integer object, that is returned unboxed again.
Thanks for the detailed explanation. I understood what you were saying, that the output stream is written as an integer type rather than a byte
I faced this problem indirectly with Spring Batch, which is using XStream. SpringBatch serializes the metadata information to XStream, but it seems to do it as Byte instead of object.
from xstream.
I don't use Spring, but in this case they are using the API of Java Serialization and this means, they must read the same types in the same sequence that they had written it before.
Now, what might have happen is, that the persisted XML has been written with a different version of the application or the Java runtime, where the serialization for an object had been changed in between (e.g. a new field in a serialized object). However, in that case it is no real limitation of XStream, but of Java serialization itself, i.e. you would have faced the same problem using Java Serialization natively.
Normally such problems can be tackled by directly implementing Java serialization functions in the affected classes, that handle the differences from an older representation, but that's typically never done... and may it be just because most devs are not even aware of such problems.
from xstream.
Related Issues (20)
- 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
- Problem of TreeSet/TreeMap HOT 4
- 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
- Alias using serialization proxy pattern ? HOT 2
- Posting/verifying signing keys used for artifacts in Maven Central? HOT 2
- xstream 1.4.4 moving from Oracle Java 1.8 to OpenJDK 1.8 HOT 1
- info required for compatible version with openjdk21 HOT 1
- Warning of use of Unsafe in JDK 23
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.