简体   繁体   中英

Eclipselink loaded object and JMS Serialization

We have a Glassfish 5 application server with severals war modules and some Java applications clients which are communicating between JMS and Rest webservices.

The server app load objects from databases using Eclipselink and, when needed, send them through JMS automatically. Now I'm facing a problem when deserializing the object on the client side because JMS throws a java.lang.ClassNotFoundException: org.eclipse.persistence.indirection.IndirectList exception. The thing is that I do not have any IndirectList object in my entity but I assume that it is EclipseLink which instanciate my object Lists as IndirectList. The question is, why when recovering the object on the client side, it tries to instantiate IndirectList instead of List or ArrayList (I put the MyObject.class in the getBody() Method of JMS) ? I can correct the error by adding eclipselink dependence on the client side but I'm not satisfied by this solution since I normally don't need it...

I hope I well explained my problem. Thank you.

The simplest way to solve a java.lang.ClassNotFoundException is to add the missing class to your classpath. It's really as simple as that.

For what it's worth, I usually discourage people from using the JMS ObjectMessage for this exact kind of reason. Unless the object you put into the message is extremely simple you wind up adding classes to your client that may not really be necessary except to deserialize another object. Also, serialization and deserialization of Java objects is quite slow. I usually recommend that applications exchange data via simple byte arrays or even use something like JSON (although JSON can be slow there are faster alternatives).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM