Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-26
5
Medium Priority
?
2,719 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 100 total points
ID: 18791852
0
 
LVL 8

Assisted Solution

by:mnrz
mnrz earned 100 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

609 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