Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse java  build path 6 59
HSSFWorkbook cannot be resolved error 10 72
map related example 6 49
web application structure 18 77
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

831 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