Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5953693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:51:45+00:00 2026-05-22T17:51:45+00:00

I am using Xstream to serializing a Job object. It looks working fine. but

  • 0

I am using Xstream to serializing a Job object. It looks working fine.

but deserializing, I have a problem:

Exception in thread "main" com.thoughtworks.xstream.io.StreamException:  : only whitespace content allowed before start tag and not . (position: START_DOCUMENT seen .... @1:1) 
    at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:78)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:137)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:130)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:109)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:94)
    at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:48)
    at com.thoughtworks.xstream.io.xml.XppDriver.createReader(XppDriver.java:44)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:845)

Did one of you get this problem before?

This is the way, I did for serializing:

XStream xstream = new XStream();                    
Writer writer = new FileWriter(new File("model.xml"));
writer.write(xstream.toXML(myModel));
writer.close();

I also try this as well:

XStream xstream = new XStream();                    
OutputStream out = new FileOutputStream("model.xml");
xstream.toXML(myModel, out);

For deserializing, I did it like this:

XStream xstream = new XStream();

xstream.fromXML("model.xml");

XML structure:

<projectCar.CarImpl> 
   <CarModel reference="../.."></CarModel>
</projectCar.CarImpl> 

If yes, I would like to hear. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:51:46+00:00Added an answer on May 22, 2026 at 5:51 pm

    fromXML does not take a filename, try:

    File xmlFile = new File("model.xml");
    xstream.fromXML(new FileInputStream(xmlFile));
    

    to read the file contents as a String.

    Also the fieldnames ‘id’ and ‘reference’ happen to be ‘system attributes’ in XStream. Using the following code:

    CarImpl myModel = new CarImpl();
    
    File xmlFile = new File("model.xml");
    
    XStream xstream = new XStream();
    xstream.useAttributeFor(String.class);
    xstream.useAttributeFor(Integer.class);
    
    Writer writer = new FileWriter(xmlFile);        
    writer.write(xstream.toXML(myModel));
    writer.close();
    
    CarImpl fromXML = (CarImpl) xstream.fromXML(new FileInputStream(xmlFile));
    System.out.println(fromXML);
    

    unmarshalling fails if the fields are called ‘id’ and ‘reference’, but succeeds otherwise. See XStream FAQ

    Take a look at the new method ‘aliasForSystemAttribute’ for a possible solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently deserializing JSON using XStream, and it has been working great. However,
I am using XStream for serializing and de-serializing an object. For example, a class
I am using xStream for serializing and de-serializing objects. But when there is &
I'm thinking of using the XStream library but I have a couple of questions/concerns.
I am using nice little piece of xstream to perform serialization. I have the
My (simple) war project builds fine using mvn:package at the command line, but fails
We serialize/deserialize XML using XStream... and just got an OutOfMemory exception. Firstly I don't
I have a problem with aliasing in XStream. I've got a set of String
I have a xml file, which is not serialized using XStream. It may be
I am using XStream to serialize an object which contains a Date field to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.