What are the consequences of a JAXB object not implementing serializable?
Asked Answered
S

1

5

I am hoping someone could clarify this for me so that I can better understand how marshalling of JAXB objects work.

From reading and looking at examples it is my understanding that a JAXB object must implement java.io.Serializable so that the object can be marshalled and unmarshalled correctly. The part that I am a bit unsure about is what happens (read: what are the consequences) when one of your JAXB objects do not implement serializable? This has happened in the past and results in errors in the log files similar to

ERROR [example.package.name.MyJaxbClass.data]DiskStorageFactory.call{503} | Disk Write of -309037891 failed: 
java.io.NotSerializableException: example.package.name.myJaxbClass$MyNonSerializedElement

Yet the rest of the code seems to work fine. How important is it for your JAXB classes to implement serializable and what happens when they do not?

Stipule answered 21/3, 2013 at 13:50 Comment(1)
Why was this tagged as spring? I see nothing Spring-specific in this question.Cabinetwork
Q
7

A JAXB (JSR-222) object is not required to implement java.io.Serializable in order for it to be converted to/from XML. The object to/from XML conversion does not occur as part of Java serialization. Of course if you do wish to serialize the objects for use with some other part of your application then you need to configure them correctly for that.

Quinonoid answered 21/3, 2013 at 13:54 Comment(1)
I think this helps clarify the issue. The serialization is not actually needed for marshalling the JAXB object but rather for anything that requires serialization after retrieving the object. For example, storing it in a session cookie. Does that sound right? Thanks for the help.Stipule

© 2022 - 2024 — McMap. All rights reserved.