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 5964053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:21:44+00:00 2026-05-22T19:21:44+00:00

I am using xStream in Java to serialize a java object from a java

  • 0

I am using xStream in Java to serialize a java object from a java library and deserializing it at the customer’s side.

I have several problems:

If I do it like this:

XStream xstream = new XStream();
xstream.setMode(XStream.ID_REFERENCES);
xstream.autodetectAnnotations(true);
Writer writer = new FileWriter(xmlFile);        
writer.write(xstream.toXML(myObject));
writer.close();

=> serializing is OK but deserializing: Exception in thread "main" com.thoughtworks.xstream.io.StreamException: : only whitespace content allowed before start tag and not . (position: START_DOCUMENT seen .... @1:1)

if I do it like this:

XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
Writer writer = new FileWriter(xmlFile);        
writer.write(xstream.toXML(myObject));
writer.close();

=> I got serialization 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)

With xml:

<Test.Platform id="1">
    <TaskImpl id="1">
          <model reference="2"/>
          <name>process</name>
    </TaskImpl>
</Test.Platform id="1">

So Any suggestion?

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-22T19:21:45+00:00Added an answer on May 22, 2026 at 7:21 pm

    so the thing that is overlooked here is how you are reading in the file. you are using

    XStream xstream = new XStream();
    xstream.fromXML("model.xml");
    

    Which is where the period(.) is coming from in the error. The method fromXML is expecting the actual XML input and not the file name. So when it parses your xml (which is “model.xml” not the actual xml) it is giving the error. The site for XStream is down right now so I can’t link to the API

    Use a FileReader/BufferedReader in order to get the contents of the XML back. Something like this should work

    XStream instream = new XStream();
    
    BufferedReader br = new BufferedReader(new FileReader("model.xml"));
    StringBuffer buff = new StringBuffer();
    String line;
    while((line = br.readLine()) != null){
       buff.append(line);
    }
    Platform p = (Platform)instream.fromXML(buff.toString());
    

    P.S. I was able to duplicate the problem, and fix it with the above

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

Sidebar

Related Questions

I'm thinking of using the XStream library but I have a couple of questions/concerns.
Is there a YAML driver for the Java XStream package? I'm already using XStream
I'm using XStream to serialize some objects to XML, and am facing a problem
I am using XStream to serialize my Objects to XML format. The formatted xml
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Previously, to read XML in UTF-8 encoding through xstream, I am using DomDriver as
Using jQuery's UI Tabs. This is my code. <div id=tabs> <ul> <li><a href=#tabs-1>Find a
Using Core Data. Let's say we have models for Team and Player. Assume: -Each
Using PyObjC , you can use Python to write Cocoa applications for OS X.

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.