How do I store my objects? XML/binary/schema

T

timasmith

Hi,

I noticed with .Net the framework provides a simple ability to
serialize an object to XML and back again.

Does Java have the same functionality?

Also, I have a system which needs to persist objects and then perform
some custom scripting on them - I assume storing objects as binary
would be ill advised due to version incompatibility - but XML would be
make need for a *huge* table - although I guess I could zip and store
them. That might be slow and a lot of overhead to extract them though.

Store binary or XML or zipped XML or as columns on tables?

thanks

Tim
 
J

James McGill

Hi,

I noticed with .Net the framework provides a simple ability to
serialize an object to XML and back again.

Does Java have the same functionality?

Java has a standard API for extensions that do XML binding, and there's
a Sun reference implementation.

http://java.sun.com/webservices/jaxb/index.jsp

I use Castor for this, though not a standard JAXB implementation, and I
find it to be excellent and pretty efficient. Many of my applications
are built starting with an XML Schema and I use Castor to automatically
generate objects from that. Starting there, it's extremely easy to
Marshall/Unmarshall objects to and from XML, and I also do database
binding to the same objects.

The problem with having a "simple" ability to marshal or unmarshal, is
that the relationship between an object and its XML representation is
not always quite so simple.

If you don't really care about the structure of the XML and don't need
precise control over naming and type conversion, you can use XStream
very simply.

Also, I have a system which needs to persist objects and then perform
some custom scripting on them - I assume storing objects as binary
would be ill advised due to version incompatibility - but XML would be
make need for a *huge* table - although I guess I could zip and store
them. That might be slow and a lot of overhead to extract them though.

I use Hibernate to map my objects (the same ones I map to XML Schema) to
a database. It's pretty efficient both in terms of storage size and
performance, but that's relative, of course. Since I specialize in a
certain type business software, I consider the benefits to data
integrity and the design-by-contract opportunities that come with xml
binding, to far outweigh performance considerations.
 
T

Thomas Fritsch

I noticed with .Net the framework provides a simple ability to
serialize an object to XML and back again.

Does Java have the same functionality?
See the classes
java.beans.XMLEncoder,
java.beans.XMLDecoder
 
T

timasmith

I did - so neither this nor Castor seems to do a deep copy of my
objects - is that a flag on either?
I have a hierarchy of objects which all need to be stored.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top