473,414 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

InvalidClassException in serialized class problem

Hi,

I hope someone can really help me.

This problem has me stumped. I have class "A" that does not implement
Serializable, but class "A" subclasses Serializable class "B". Therefore,
when reading class "A" it should be read as a serialized class. Class "A"
has one data member "private char m_operator".

When I compile with JDK 1.3.1_17, the data file is read correctly.
m_operator is read as a char.

When I compile with JDK 1.5.0_06, the data file is read incorrectly.
m_operator is tried to be read as a String; thus, the InvalidClassException.

I tried to add the method "private void readObject(ObjectInputStream in)" to
class "A" so that I could get the fields using ObjectInputStream.Field inner
class. With the inner class I could then write:

private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
ObjectInputStream.Field fields = in.getFields();
try
{
m_operator = fields.get("m_operator", ' ');
}
catch (IllegalArgumentException exception)
{
try
{
String operator = (String) fields.get("m_operator", "+");
if ((operator != null) && (operator.length() > 0))
{
m_operator = operator.charAt(0);
}
else
{
throw exception
}
}
catch (IllegalArgumentException iaException)
{
throw iaException
}
}
}

I have 2 questions that I hope someone can help explain:

(1) Why is JDK 1.5.0_06 reading m_operator as a String?

(2) Why isn't my readObject() method being called? A serialized class is
supposed to override the default and call this method instead. I tried
implementing Serializable on class "A:, but it had no effect.

Thank you,
Don
May 5 '06 #1
0 2524

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
0
by: hdsj | last post by:
Hi All, Hoping someone can solve a problem for me. I am modifying the schema for a rather complex web service written in VB.NET. The services uses a large number of serialized classes to...
0
by: Wim Hollebrandse | last post by:
Here's the scenario. I'm serializing a particular object, which contains other objects as properties. I have this particular enum type that won't get included in the serialized XML. For...
7
by: Neal Andrews | last post by:
Hi All, Does anyone know how to stop Events from being serialized in a class that uses the <Serializable()> attribute? I have tried using the <NonSerialized()> attribute but for some bizarre...
0
by: Marty Cruise | last post by:
I use a custom class to hold several other custom classes (some are collections). Each child class has properties, methods, etc. In some of these methods, I need to use particular information...
5
by: EqDev | last post by:
I have a class that is a control derived from UserControl. I want to use serialization and deserialization with this calss but I get an exception "Cannot serialize member...
3
by: CindyRob | last post by:
I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix 82202, Visual studio .NET 2003 with hotfix 823639. I have generated a proxy class using wsdl.exe from a schema that has an...
2
by: Gasnic | last post by:
Hi I need to create a .NET object that will be serialized into the following xml structure ( I can't change the XML schema) <Root> <Record> <Field1>data1</Field1> <Field2>data2</Field2>...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.