Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problems with serialization/deserialization
Problems with serialization/deserialization [message #632629] Wed, 13 October 2010 16:10 Go to next message
Sorin Fagateanu is currently offline Sorin FagateanuFriend
Messages: 46
Registered: July 2009
Member
Hello,

I'm trying to make a serialization/deserialization of an UML model using java Serializable interface.
My scope is to create an object, make a serialization (so I can save it in a database) and a deserialization (when I retrieve it from database).

In the serialization/deserialization process, problems appeared : java.io.NotSerializableException was thrown when trying to serialize the object with writeObject method.
My solution was to take EMF sources and rewrite the classes with problems, adding "implements java.io.Serializable" so they can accept serialization.
Some modified classes :
- org.eclipse.emf.common.notify.Notifier
- org.eclipse.emf.common.util.URI;
- org.eclipse.emf.ecore.resource.URIHandler;
- org.eclipse.emf.ecore.resource.URIConverter;
- org.eclipse.emf.ecore.util.ExtendedMetaData; etc.

After these changes, the object was successfully serialized.
The big problem was with deserialization. I encountered this error when trying to deserialize with readObject method :

java.lang.NullPointerException
	at org.eclipse.emf.ecore.util.EcoreEMap.newEntry(EcoreEMap.java:182)
	at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:593)
	at org.eclipse.emf.common.util.BasicEMap.readObject(BasicEMap.java:1557)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at org.eclipse.emf.common.util.BasicEList.readObject(BasicEList.java:775)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at org.eclipse.emf.common.util.BasicEList.readObject(BasicEList.java:775)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at org.eclipse.emf.common.util.BasicEList.readObject(BasicEList.java:775)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at teste.BootstrapListener.deserialize(BootstrapListener.java:156)

After making some investigations, I discovered that the problem is in org.eclipse.emf.common.util.BasicEMap : some fields (like delegateEList) are "transient" by default and they are deserialized as null.

Does anybody else has encountered this type of error? If yes can you please guide me?

Thank you in advance for your help,
Sorin.
Re: Problems with serialization/deserialization [message #632673 is a reply to message #632629] Wed, 13 October 2010 20:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30559
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070903000609020407060305
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Sorin,

I think it's a losing battle to take the approach you've taken. This
bugzilla takes a cleaner approach.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=245014

Even then, you're likely better off to put things in a wrapper that's
specialized to use a resource to serialize and deserialize.


Sorin Fagateanu wrote:
> Hello,
>
> I'm trying to make a serialization/deserialization of an UML model
> using java Serializable interface.
> My scope is to create an object, make a serialization (so I can
> save it in a database) and a deserialization (when I retrieve it from
> database).
> In the serialization/deserialization process, problems appeared :
> java.io.NotSerializableException was thrown when trying to serialize
> the object with writeObject method. My solution was to take EMF
> sources and rewrite the classes with problems, adding "implements
> java.io.Serializable" so they can accept serialization.
> Some modified classes : - org.eclipse.emf.common.notify.Notifier
> - org.eclipse.emf.common.util.URI;
> - org.eclipse.emf.ecore.resource.URIHandler;
> - org.eclipse.emf.ecore.resource.URIConverter;
> - org.eclipse.emf.ecore.util.ExtendedMetaData; etc.
>
> After these changes, the object was successfully serialized.
> The big problem was with deserialization. I encountered this error
> when trying to deserialize with readObject method :
>
> java.lang.NullPointerException
> at org.eclipse.emf.ecore.util.EcoreEMap.newEntry(EcoreEMap.java :182)
> at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:593 )
> at
> org.eclipse.emf.common.util.BasicEMap.readObject(BasicEMap.j ava:1557)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.readObject(Unknown Source)
> at
> org.eclipse.emf.common.util.BasicEList.readObject(BasicEList .java:775)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.readObject(Unknown Source)
> at
> org.eclipse.emf.common.util.BasicEList.readObject(BasicEList .java:775)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.readObject(Unknown Source)
> at
> org.eclipse.emf.common.util.BasicEList.readObject(BasicEList .java:775)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
> at java.io.ObjectInputStream.readSerialData(Unknown Source)
> at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
> at java.io.ObjectInputStream.readObject0(Unknown Source)
> at java.io.ObjectInputStream.readObject(Unknown Source)
> at
> teste.BootstrapListener.deserialize(BootstrapListener.java:1 56)
> After making some investigations, I discovered that the problem is
> in org.eclipse.emf.common.util.BasicEMap : some fields (like
> delegateEList) are "transient" by default and they are deserialized as
> null.
>
> Does anybody else has encountered this type of error? If yes can
> you please guide me?
>
> Thank you in advance for your help,
> Sorin.
>

--------------070903000609020407060305
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Sorin,<br>
<br>
I think it's a losing battle to take the approach you've taken.  This
bugzilla takes a cleaner approach.<br>
<blockquote><a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=245014">https://bugs.eclipse.org/bugs/show_bug.cgi?id=245014</a><br>
</blockquote>
Even then, you're likely better off to put things in a wrapper that's
specialized to use a resource to serialize and deserialize.<br>
<br>
<br>
Sorin Fagateanu wrote:
<blockquote cite="mid:i94lgl$k17$1@news.eclipse.org" type="cite">Hello,
<br>
<br>
    I'm trying to make a serialization/deserialization of an UML model
using java Serializable interface.
<br>
    My scope is to create an object, make a serialization (so I can
save it in a database) and a deserialization (when I retrieve it from
database).       
<br>
    In the serialization/deserialization process, problems appeared :
java.io.NotSerializableException was thrown when trying to serialize
the object with writeObject method.     My solution was to take EMF
sources and rewrite the classes with problems, adding "implements
java.io.Serializable" so they can accept serialization.
<br>
    Some modified classes :     -
org.eclipse.emf.common.notify.Notifier
<br>
    - org.eclipse.emf.common.util.URI;
<br>
    - org.eclipse.emf.ecore.resource.URIHandler;
<br>
    - org.eclipse.emf.ecore.resource.URIConverter;
<br>
    - org.eclipse.emf.ecore.util.ExtendedMetaData; etc.
<br>
<br>
    After these changes, the object was successfully serialized.
<br>
    The big problem was with deserialization. I encountered this error
when trying to deserialize with readObject method :
<br>
    
<br>
java.lang.NullPointerException
<br>
    at
org.eclipse.emf.ecore.util.EcoreEMap.newEntry(EcoreEMap.java :182)
<br>
    at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:593 )
<br>
    at
org.eclipse.emf.common.util.BasicEMap.readObject(BasicEMap.j ava:1557)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
<br>
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
<br>
    at java.lang.reflect.Method.invoke(Unknown Source)
<br>
    at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject(Unknown Source)
<br>
    at
org.eclipse.emf.common.util.BasicEList.readObject(BasicEList .java:775)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
<br>
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
<br>
    at java.lang.reflect.Method.invoke(Unknown Source)
<br>
    at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject(Unknown Source)
<br>
    at
org.eclipse.emf.common.util.BasicEList.readObject(BasicEList .java:775)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
<br>
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
<br>
    at java.lang.reflect.Method.invoke(Unknown Source)
<br>
    at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject(Unknown Source)
<br>
    at
org.eclipse.emf.common.util.BasicEList.readObject(BasicEList .java:775)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<br>
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
<br>
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
<br>
    at java.lang.reflect.Method.invoke(Unknown Source)
<br>
    at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
<br>
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
<br>
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject0(Unknown Source)
<br>
    at java.io.ObjectInputStream.readObject(Unknown Source)
<br>
    at
teste.BootstrapListener.deserialize(BootstrapListener.java:1 56)        <br>
    After making some investigations, I discovered that the problem is
in org.eclipse.emf.common.util.BasicEMap : some fields (like
delegateEList) are "transient" by default and they are deserialized as
null.
<br>
    
<br>
    Does anybody else has encountered this type of error? If yes can
you please guide me?
<br>
<br>
Thank you in advance for your help,
<br>
Sorin.
<br>
<br>
</blockquote>
</body>
</html>

--------------070903000609020407060305--
Previous Topic:Persisting with cross references fails
Next Topic:How retrieve DefaultValue of a Property
Goto Forum:
  


Current Time: Wed Oct 23 14:09:20 GMT 2019

Powered by FUDForum. Page generated in 0.02920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top