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

  • SEARCH
  • Home
  • 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 7183241
In Process

The Archive Base Latest Questions

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

I’m trying to write a class that would enable me to just write .save();

  • 0

I’m trying to write a class that would enable me to just write .save(); to make a permanent copies of child classes. I’ve created a method that creates the xml:

public boolean save() throws IOException{
    XStream xstream = new XStream(new KXml2Driver());

    FileWriter extenceWriter = new FileWriter(saveFile);
    xstream.alias(this.getClass().getSimpleName(), this.getClass());
    xstream.toXML(this, extenceWriter);

    return saveFile.exists();
}

and another one that should read it:

public Object loadFile(String path) throws FileNotFoundException{
    File file = new File(appRootDIR + File.separator + path);

    XStream xstream = new XStream(new KXml2Driver());
    FileReader extenceReader = new FileReader(file);

    return xstream.fromXML(extenceReader);
}

The problem is that i get a com.thoughtworks.xstream.mapper.CannotResolveClassException when i try to use loadFile().
I’ve checked google and the closest hit was that different instances of xstream can’t communicate.
This could be solved by moving xstream to a class field, but then I get some errors regarding to the matter that xstream can’t serialise itself.

Is there a good way to implement both read and write methods in a class without having to create a xstream instance outside of the box?

  • 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-28T17:56:23+00:00Added an answer on May 28, 2026 at 5:56 pm

    Because you are using an alias in save(), the simple class name rather than the fully qualified class name is written to the XML. This makes loadFile() unable to figure out what class it is referring to.

    You can fix this in one of two ways:

    1. Don’t using aliasing – simple, but the XML won’t be as clean-looking.
    2. Make a method that registers all the aliases you want to use on an XStream instance, and call that method from both save() and loadFile() so that they can operate with the same set of aliases.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.