java - Jackson binary serialization for custom class -
i trying serialize class using jackson in binary format , struggling after trying number of different alternatives. hoping can help.
my custom class looks like:
package com.common; import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstream; import java.util.list import org.apache.jena.rdf.model.model; import org.apache.jena.rdf.model.rdfnode; import org.apache.jena.rdf.model.statement; import org.apache.jena.util.filemanager; import org.apache.jena.util.iterator.extendediterator; import com.fasterxml.jackson.annotation.jsoncreator; import com.fasterxml.jackson.databind.jsonnode; import com.fasterxml.jackson.databind.objectmapper; import com.fasterxml.jackson.databind.node.arraynode; import com.quick.rdfmain; import com.quick.exim.importer; import com.quick.exim.sqejsontordfimporter; import com.quick.trans.rdfformulatosparqltranslator; /** * reasoning request, request representation based on rdf standards. * * */ public class rdfrequest{ private simplesparqlquery query = null; // todo: make more sense context model? // private contextwrapper context = null; // private configwrapper config = null; list<statement> context = null; list<statement> config = null; public rdfrequest(simplesparqlquery query,list<statement> context,list<statement> config) { this.query = query; this.context = context; this.config = config; } public rdfrequest(){ } public rdfrequest(string querypath, string driverpath, string vehiclepath) throws ioexception { string absolutequerypath = rdfmain.class.getclassloader().getresource(querypath).getpath(); importer<arraynode, ?> importer = null; arraynode inputnode = null; rdfnode internalfrom = null; objectmapper mapper = new objectmapper(); inputstream = new fileinputstream(absolutequerypath); jsonnode node = mapper.readtree(is); rdfformulatosparqltranslator translator = new rdfformulatosparqltranslator(); model inputmodel; rdfrequest request = null; // import query json jsonnode formulanode = node.get("formula"); if (formulanode != null) { importer = new sqejsontordfimporter(); inputnode = (arraynode) formulanode; } if (importer != null && inputnode != null) { internalfrom = (rdfnode) importer.importfrom(inputnode); inputmodel = internalfrom.getmodel(); query= translator.translate(inputmodel); } // load context data model contextdata = filemanager.get().loadmodel(driverpath, "n3"); contextdata = filemanager.get().readmodel(contextdata, vehiclepath, "n3"); extendediterator<statement> statements = contextdata.liststatements(); context = statements.tolist(); return; } public simplesparqlquery getquery() { return query; } public void setquery(simplesparqlquery query) { this.query = query; } public list<statement> getcontext() { return context; } public void setcontext(list<statement> context) { this.context = context; } public list<statement> getconfig() { return config; } public void setconfig(list<statement> config) { this.config = config; } }
take 1
public void sendmessageusingjackson(rdfrequest message,string topic){ system.out.println("inside rdf request client "+this.clientid+ " sending message"); system.out.println("topic on "+this.clientid+" publishing "+topic); this.messageproducer = getmessageproducer(topic); try { objectmapper mapper = new objectmapper(); byte[] jsonbytes = mapper.writevalueasbytes(message); bytesmessage m = getsession().createbytesmessage(); m.writebytes(jsonbytes); this.messageproducer.send(m); this.messageproducer.close(); } catch (jmsexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } }
when execute this, throws:
com.fasterxml.jackson.databind.jsonmappingexception: conflicting getter definitions property "uri": org.apache.jena.graph.node#geturi(0 params) vs org.apache.jena.graph.node#isuri(0 params) (through reference chain: com.nuance.nrf.common.rdfrequest["query"]->com.nuance.nrf.common.simplesparqlquery["variables"]->java.util.arraylist[0]) @ com.fasterxml.jackson.databind.serializerprovider._createandcacheuntypedserializer(serializerprovider.java:838) @ com.fasterxml.jackson.databind.serializerprovider.findvalueserializer(serializerprovider.java:387) @ com.fasterxml.jackson.databind.ser.impl.propertyserializermap.findandaddserializer(propertyserializermap.java:38) @ com.fasterxml.jackson.databind.ser.std.asarrayserializerbase._findandadddynamic(asarrayserializerbase.java:270) @ com.fasterxml.jackson.databind.ser.impl.indexedlistserializer.serializecontents(indexedlistserializer.java:96) @ com.fasterxml.jackson.databind.ser.impl.indexedlistserializer.serializecontents(indexedlistserializer.java:21) @ com.fasterxml.jackson.databind.ser.std.asarrayserializerbase.serialize(asarrayserializerbase.java:186) @ com.fasterxml.jackson.databind.ser.beanpropertywriter.serializeasfield(beanpropertywriter.java:569) @ com.fasterxml.jackson.databind.ser.std.beanserializerbase.serializefields(beanserializerbase.java:597) @ com.fasterxml.jackson.databind.ser.beanserializer.serialize(beanserializer.java:142) @ com.fasterxml.jackson.databind.ser.beanpropertywriter.serializeasfield(beanpropertywriter.java:569) @ com.fasterxml.jackson.databind.ser.std.beanserializerbase.serializefields(beanserializerbase.java:597) @ com.fasterxml.jackson.databind.ser.beanserializer.serialize(beanserializer.java:142) @ com.fasterxml.jackson.databind.ser.defaultserializerprovider.serializevalue(defaultserializerprovider.java:118) @ com.fasterxml.jackson.databind.objectmapper._configandwritevalue(objectmapper.java:2718) @ com.fasterxml.jackson.databind.objectmapper.writevalueasbytes(objectmapper.java:2233) @ com.nuance.research.jms.jmshook.sendmessageusingjackson(jmshook.java:334) @ com.nuance.research.main.rilimpl.exchangemessage(rilimpl.java:28) @ com.nuance.research.main.riltestclient.main(riltestclient.java:35) caused by: java.lang.illegalargumentexception: conflicting getter definitions property "uri": org.apache.jena.graph.node#geturi(0 params) vs org.apache.jena.graph.node#isuri(0 params) @ com.fasterxml.jackson.databind.introspect.pojopropertybuilder.getgetter(pojopropertybuilder.java:190) @ com.fasterxml.jackson.databind.introspect.pojopropertybuilder.getaccessor(pojopropertybuilder.java:283) @ com.fasterxml.jackson.databind.ser.beanserializerfactory.removeignorabletypes(beanserializerfactory.java:678) @ com.fasterxml.jackson.databind.ser.beanserializerfactory.findbeanproperties(beanserializerfactory.java:557) @ com.fasterxml.jackson.databind.ser.beanserializerfactory.constructbeanserializer(beanserializerfactory.java:373) @ com.fasterxml.jackson.databind.ser.beanserializerfactory.findbeanserializer(beanserializerfactory.java:268) @ com.fasterxml.jackson.databind.ser.beanserializerfactory._createserializer2(beanserializerfactory.java:213) @ com.fasterxml.jackson.databind.ser.beanserializerfactory.createserializer(beanserializerfactory.java:152) @ com.fasterxml.jackson.databind.serializerprovider._createuntypedserializer(serializerprovider.java:873) @ com.fasterxml.jackson.databind.serializerprovider._createandcacheuntypedserializer(serializerprovider.java:833) ... 18 more
i have tried using other ways , have been struggling since 2 days now. have use external library called apache jena , error getting above coming methods related classes in package. appreciate can or pointers how workaround. want convert rdfrequest object bytes , send on jms bytemessage. happy provide clarification.
thank you.
Comments
Post a Comment