File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes the XMLEncoder (java.beans) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "the XMLEncoder (java.beans)" Watch "the XMLEncoder (java.beans)" New topic

the XMLEncoder (java.beans)

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

I try to serilaize an Object with the XMLEncoder but all that I got is an
Exception because I don't have a default constuctor
and if I create one I get :
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_05" class="java.beans.XMLDecoder">
<object class="MyClass"/>

No others properties!
What I do wrong.

Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
It would help if you would post your Java class for us to see as well.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

and here comes the class :


Edit Comment: Added [ code ] [ / code ] tags.
[ November 04, 2004: Message edited by: Madhav Lakkapragada ]
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Though I don't know no much about XMLEncoder, I got the impression that you need a constructor without any parameters.
As we all know Java creates automatically default constructor, if there is no constructor in class.
But your class has:

there is no without-parameters constructor.

Often things that work with introspection impose the restriction that the class has a constructor without parameters.

So you might put in a

and set property name other way.

[ November 04, 2004: Message edited by: Axel Janssen ]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

I tried with an default constructor but then my xml file was :
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_05" class="java.beans.XMLDecoder">
<object class="com.oce.prismapro.xpdc.util.presistentcomposite.Node"/>
I agree. Here's the link:
subject: the XMLEncoder (java.beans)
It's not a secret anymore!