• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Make an interface serializable

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to pass a result set interface from a server to client using JMS. But the particular interface is not implementing the serializable interface. And the default class implementation also does not implement the Serializalbe interface.

Is there a way i can wrap the interface as serializable and use it in messaging?

Interface to be made serializable -> TupleQueryResult

<Edit> Adding the exception received </edit>

java.lang.RuntimeException: org.openrdf.query.impl.TupleQueryResultImpl
at org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:104)
at org.apache.activemq.command.ActiveMQObjectMessage.setObject(ActiveMQObjectMessage.java:155)
at org.apache.activemq.ActiveMQSession.createObjectMessage(ActiveMQSession.java:330)
at JMSObjectDelegator.processMessage(JMSObjectDelegator.java:127)
at JMSObjectDelegator.consumeMessagesAndClose(JMSObjectDelegator.java:156)
at JMSObjectDelegator.run(JMSObjectDelegator.java:109)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.NotSerializableException: org.openrdf.query.impl.TupleQueryResultImpl
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at java.util.HashMap.writeObject(HashMap.java:1001)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:98)



Thank you!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can't change the interface or the implementing class yourself then no, there is no way to force it to be serializable.

What you can do is get the data out of the object, and put it in a data transfer object that you write yourself, and which you make serializable. Then you send that DTO over the network (or whatever else you want to do with the serialized object).

There might be a good reason why TupleQueryResult is not serializable. I don't know what a TupleQueryResult is, but maybe it's comparable to a JDBC ResultSet. A JDBC ResultSet often has a link back to the database (via a network connection). When you get the next result from the ResultSet, it may actually ask the database for the next row via this network connection. You cannot serialize the ResultSet, send it to another computer and de-serialize it there, because the network connection between the database server and the original client can't be transferred like that to another client.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper.
Yes the TupleQueryResult is like a ResultSet. I even foolishly wrote a custom class that extends the TupleQueryResultImpl only to find that cast from the higher TupleQueryResultImpl to the lower custom class cannot be done. We were using DTOs to transfer between the server and the client previously. Just attempted whether we can make the server code generic so that server just queries the database and just returns the result set and the client should take the specific info from the result set. Hope that is not possible now!

My trial class
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tried serializing the BindingSet that was marked Serializable. But again I got the below error.

Interface -> BindingSet

Class -> MapBindingSet

My bit of serialization class code..



Error ->

java.lang.RuntimeException: org.openrdf.query.impl.MapBindingSet
at org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:104)
at org.apache.activemq.command.ActiveMQObjectMessage.setObject(ActiveMQObjectMessage.java:155)
at org.apache.activemq.ActiveMQSession.createObjectMessage(ActiveMQSession.java:330)
at JMSObjectDelegator.processMessage(JMSObjectDelegator.java:128)
at JMSObjectDelegator.consumeMessagesAndClose(JMSObjectDelegator.java:157)
at JMSObjectDelegator.run(JMSObjectDelegator.java:110)
at java.lang.Thread.run(Thread.java:662)Creating obj

Caused by: java.io.NotSerializableException: org.openrdf.query.impl.MapBindingSet
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at java.util.HashMap.writeObject(HashMap.java:1001)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:98)

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems that the custom third party API that surrounds the above mentioned classes are not serializable and hence the exception.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic