XML or Serialization? Need advice!

Discussion in 'Java' started by Tobi Krausl, Nov 19, 2003.

  1. Tobi Krausl

    Tobi Krausl Guest


    I'm developing an application in which there's the need given to
    manage some kind of status-information. Everytime the status changes
    the corresponding data-structure containing the status-information
    must be updated and stored in a file.

    I was thinking of using Serialization and maybe a TreeMap for holding
    the status-data. Using this method would allow to save/restore the
    TreeMap-object pretty easily, right? However, I'm not sure whether
    this is really a good solution.

    An alternative to Serialization would in my opinion be to use XML
    (preferred DOM). I think that I'll never need some special features
    provided by XML in terms of my problem.

    So I'm thinking about what kind of persistence- and storage-
    mechanisms I should use?! Performance isn't an issue too, so I
    wouldn't mind that XML is a little bit slower than Serialization.

    What would you use and why?
    If you would use XML (DOM), which Parser (Standard API, JDOM, XERCES,
    DOM4J) and why?

    Thank you very much,
    Tobi Krausl, Nov 19, 2003
    1. Advertisements

  2. I was working on a project where some session data used to be serialized
    and stored for recovery retrieval. It worked good until the need rose to
    upgrade the application. Deserialization of the data generated by the older
    version of out application was not possible anymore and we lost some data.

    So, if you recognize yourself in similar situation you might consider using
    XML. Which XML parser you use actually depends on your preferences. I like
    Davor Cengija, Nov 19, 2003
    1. Advertisements

  3. During my currecnt project I have been having difficulties determining what
    to use, serialization or XML. I decided to use XML when it is more flexible
    and "debuggable", you get a good overview of your objects with that. I made
    a mistake trying to store an object that had around 120000 integers, but it
    got a littlebit to big files, now I'm using BufferedImage for that. I use
    XML for basicly all my storing of data exept images and image-like objects.

    Cheers, Peter
    Peter the Swede, Nov 19, 2003
  4. Hi Tobi!

    Am 19 Nov 2003 01:01:26 -0800 schrieb Tobi Krausl:
    I'd prefer XMLEncoding. If you take a look in the api-docs Sun placed a
    notice for many classes (e.g. JFrame): serialized objects won't be
    compatible to future releases of Swing.

    I'm not sure if this is a only-swing-related issue, but it won't make sense
    to use two different storing concepts...

    HTH, Michael.
    Michael Holtermann, Nov 19, 2003
  5. Unnecessary and fixable by setting an explicit serialVersionUID.
    Michael Borgwardt, Nov 19, 2003
  6. It is.
    It doesn't make sense to serialize GUI components in the first place.
    Michael Borgwardt, Nov 19, 2003
  7. Tobi Krausl

    Tobi Krausl Guest

    Ok, tnx guys!
    I guess that I'll use XML (JAXP and DOM) for my problem. Though it may
    take longer to implement it, I guess it's worth to do it. Another
    Issue I'll come across will be how to wrap my XML-based
    status-handling-class as a ListModel for JList...

    Tobi Krausl, Nov 20, 2003
  8. You may want to take a look at java.beans.XMLEncoder, it could save you a
    lot of work. And a status class should be easy to transfer into a bean.

    Stefan Tiemann
    Stefan Tiemann, Dec 2, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.