0

I get a NotSerializableException when I want to serialize an Object that is currently shown by Vaadin.

The structure is like this:

Vaadin UI <--- serialize / deserialize --- > Hibernate/JPA Postgres Database

Vaadin shows objects that are requested from the Database via IPC, but when I manipulate the object and want to save it again by serializing it and sending it over to the controller I get the following Exception:

java.io.NotSerializableException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
 at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
 at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
 at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
 at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
 at java.util.LinkedList.writeObject(LinkedList.java:1118)
 at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)

I tried to:

Request -> manipulate -> Save | works

Request -> show in Vaadin -> manipulate in Vaadin-> Save | doesn't work

Why does the Serializer want to AnnotationConfigEmbeddedWebApplicationContext and is there a workaround? Can I remove it beforehand?

Splitframe
  • 406
  • 3
  • 16

1 Answers1

1

Spring components are usually not serializable (or should not be serialized at all).

Injecting Spring components in Vaadin components linked to a Vaadin UI is tricky because them should be declared as transient and re-populated after deserialization..

I wrote a small library jdal-aop to ease the process, using spring-aop serializable proxies.

for example

public class MainLayout extends VerticalLayout {

    @Autowired
    @SerializableProxy  // make this Dao serializable
    private CustomerDao customerDao;
} 

It could be useful for you.

Jose Luis Martin
  • 10,459
  • 1
  • 37
  • 38