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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:28:36+00:00 2026-05-28T19:28:36+00:00

I’m trying to put into XML-file some data. Here is the code: @Test public

  • 0

I’m trying to put into XML-file some data. Here is the code:

@Test
public void TestProximities() {

    // Create a proximity 
    ISpaceComponent solarSystem = Init.createSolarSystemProximities();
    solarSystem.runTtest();

    Path filePath = Paths.get("c:\\temp\\junk.bin");

    File xmlFile = new File("c:\\temp\\");
    boolean success = xmlFile.mkdirs();
    if (!success && ! xmlFile.exists() ) {
        // Directory creation failed
        System.out.println("Failed to create a file: " + filePath);
    }

    try {
        XMLEncoder fileXml = new XMLEncoder( new BufferedOutputStream( new FileOutputStream("c:\\temp\\junk.xml") ) );
        fileXml.writeObject(solarSystem);
        fileXml.flush();
        fileXml.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());

    }

}

Init.createSolarSystemProximities():

public static ISpaceComposite createSolarSystemProximities() {

    // Proximities
    ISpaceComposite solarSystem = new SpaceComposite("The Solar System");
    solarSystem.addComponent(new Star("Sol"));      

    ISpaceComposite MercuryProximity = new SpaceComposite("Mercury proximity");
    MercuryProximity.addComponent(new Planet("Mercury"));
    solarSystem.addComponent(MercuryProximity);

    ISpaceComposite VenusProximity = new SpaceComposite("Venus proximity");
    VenusProximity.addComponent(new Planet("Venus"));
    solarSystem.addComponent(VenusProximity);

    ISpaceComposite EarthProximity = new SpaceComposite("Earth proximity");
    EarthProximity.addComponent(new Planet("The Earth"));
    EarthProximity.addComponent(new Moon("The Moon"));
    solarSystem.addComponent(EarthProximity);

    ISpaceComposite MarsProximity = new SpaceComposite("Mars proximity");
    MarsProximity.addComponent(new Planet("Mars"));
    MarsProximity.addComponent(new Moon("Phobos"));
    MarsProximity.addComponent(new Moon("Deimos"));
    solarSystem.addComponent(MarsProximity);

    return solarSystem;

} 

And the space composite class is looking like this:

public class SpaceComposite extends SpaceComponent implements ISpaceComposite {
    public static final long serialVersionUID = Data.serialVersionUID;
    private ArrayList<ISpaceComponent> _components;
private int _currentMoonIndex;

}

Also ‘SpaceComposite’ has default prameterless constructor. But the only thing, which is inserted into a file, is its name, derrived from the ‘SpaceComponent’ class

public abstract class SpaceComponent implements ISpaceComponent, Serializable{
    private String _title;
    public static final long serialVersionUID = Data.serialVersionUID;

    // Default constructor
    public SpaceComponent(){
        _title = "";
    }
 }

How can I solve this problem?

  • 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-28T19:28:38+00:00Added an answer on May 28, 2026 at 7:28 pm

    XmlEncoder captures properties using JavaBean conventions. It works by cloning the object graph and recording the steps that were necessary to create the clone. A class that you would like to use with XmlEncoder without any customizations needs to follow JavaBeans conventions (getXYZ/setXYZ for properties or isAbc/setAbc for boolean properties, etc.) My guess is that the only property available like that in your class is Name, hence it’s the only one being serialized.

    The article at the link also explains how you can customize the process by providing your own persistence delegate, but I would try adding getters/setters first to see if that is enough to make it work.

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

Sidebar

Related Questions

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
I have just tried to save a simple *.rtf file with some websites and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.