Solved

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

Posted on 2007-03-26
5
2,455 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:mayankeagle
ID: 18793547
Try using Castor instead of XMLBeans - www.castor.org
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now