Solved

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

Posted on 2007-03-26
5
2,589 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

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

Suggested Solutions

Title # Comments Views Activity
ejb mdb examples 1 36
printf performancy 11 99
Fast way to search item into Java Array (Rhino compatible) 2 46
activeMQ Queue Messages Enqueued and Messages Dequeued 1 100
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

738 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