Solved

How to serialize java.math.BigDecimal using java.beans.XMLEncoder --- URGENT

Posted on 2007-03-26
5
2,627 Views
Last Modified: 2008-01-09
When tried to serialize java.math.BigDecimal using java.beans.XMLEncoder it has given the following error.

java.lang.InstantiationException: java.math.BigDecimal
Continuing ...
java.lang.Exception: discarding statement XMLEncoder0.writeObject(BigDecimal0);
Continuing ...

OS: Windows XP
eclipse IDE,Tomcat 5.0.19
0
Comment
Question by:yasoda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
el_dios earned 25 total points
ID: 18791852
0
 
LVL 8

Assisted Solution

by:mnrz
mnrz earned 25 total points
ID: 18791883
hi

if you dont want that BigDecimal to be serialized you may mark it with "transient"

for example:
public class YourClass implements Serializable{
...
   private transient BigDecimal myDecimal;

}

but if you need to serialize that instance variable, you should put two following methods in your class definition and customize serialization:

private void writeObject(ObjectOutputStream os) {
try {
os.defaultWriteObject();
os.writeDouble(myDecimal.doubleValue());
} catch (Exception e) { e.printStackTrace(); }
}

private void readObject(ObjectInputStream is) {
try {
is.defaultReadObject();
myDecimal = BigDecimal.valueOf((is.readDouble()));
} catch (Exception e) { e.printStackTrace(); }
}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18793547
Try using Castor instead of XMLBeans - www.castor.org
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question