Giter Site home page Giter Site logo

Comments (6)

joehni avatar joehni commented on July 17, 2024 1

BTW: Just using a formatter that sorts the members of a class into a different order might cause such problems...

from xstream.

joehni avatar joehni commented on July 17, 2024

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.

thxwelchs avatar thxwelchs commented on July 17, 2024

@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.

joehni avatar joehni commented on July 17, 2024

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.

thxwelchs avatar thxwelchs commented on July 17, 2024

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.

joehni avatar joehni commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.