inheritance - Abstract types can only be instantiated with additional type information - OSGI -
i using mongojack on osgi stack. below exception getting:
set 29, 2015 3:12:59 pm com.mongodb.dbportpool goterror advertÊncia: emptying dbportpool localhost/127.0.0.1:27017 b/c of error org.codehaus.jackson.map. jsonmappingexception: can not construct instance of api.book, problem: abstract types can instantiated additional type information @ [source: de.undercouch.bson4jackson.io.littleendianinputstream@4fe0026c; pos: 0] @ org.codehaus.jackson.map.jsonmappingexception.from(jsonmappingexception.java:163) @ org.codehaus.jackson.map.deser.stddeserializationcontext.instantiationexception(stddeserializationcontext.java:233) @ org.codehaus.jackson.map.deser.abstractdeserializer.deserialize(abstractdeserializer.java:60) @ org.codehaus.jackson.map.objectmapper._readvalue(objectmapper.java:2704) @ org.codehaus.jackson.map.objectmapper.readvalue(objectmapper.java:1315) @ net.vz.mongodb.jackson.internal.stream.jacksondbdecoder.decode(jacksondbdecoder.java:62) @ com.mongodb.response.(response.java:83) @ com.mongodb.dbport.go(dbport.java:142) @ com.mongodb.dbport.call(dbport.java:92) @ com.mongodb.dbtcpconnector.innercall(dbtcpconnector.java:244) @ com.mongodb.dbtcpconnector.call(dbtcpconnector.java:216) @ com.mongodb.dbapilayer$mycollection.__find(dbapilayer.java:288) @ com.mongodb.dbapilayer$mycollection.__find(dbapilayer.java:273) @ com.mongodb.dbcursor._check(dbcursor.java:368) @ com.mongodb.dbcursor._hasnext(dbcursor.java:459) @ com.mongodb.dbcursor.hasnext(dbcursor.java:484) @ net.vz.mongodb.jackson.dbcursor.hasnext(dbcursor.java:315) @ mongo.bookinventorymongo.listbooks(bookinventorymongo.java:44) @ mongo.bookinventorymongo.start(bookinventorymongo.java:58) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ org.apache.felix.dm.invocationutil.invokemethod(invocationutil.java:111) @ org.apache.felix.dm.invocationutil.invokecallbackmethod(invocationutil.java:66) @ org.apache.felix.dm.impl.componentimpl.invokecallbackmethod(componentimpl.java:688) @ org.apache.felix.dm.impl.componentimpl.invoke(componentimpl.java:679) @ org.apache.felix.dm.impl.componentimpl.bindservice(componentimpl.java:624) @ org.apache.felix.dm.impl.componentimpl.access$400(componentimpl.java:52) @ org.apache.felix.dm.impl.componentimpl$7.run(componentimpl.java:181) @ org.apache.felix.dm.impl.serialexecutor$1.run(serialexecutor.java:47) @ org.apache.felix.dm.impl.serialexecutor.schedulenext(serialexecutor.java:84) @ org.apache.felix.dm.impl.serialexecutor.access$000(serialexecutor.java:33) @ org.apache.felix.dm.impl.serialexecutor$1.run(serialexecutor.java:50) @ org.apache.felix.dm.impl.serialexecutor.schedulenext(serialexecutor.java:84) @ org.apache.felix.dm.impl.serialexecutor.access$000(serialexecutor.java:33) @ org.apache.felix.dm.impl.serialexecutor$1.run(serialexecutor.java:50) @ org.apache.felix.dm.impl.serialexecutor.schedulenext(serialexecutor.java:84) @ org.apache.felix.dm.impl.serialexecutor.execute(serialexecutor.java:68) @ org.apache.felix.dm.impl.componentimpl.calculatestatechanges(componentimpl.java:231) @ org.apache.felix.dm.impl.componentimpl.start(componentimpl.java:399) @ org.apache.felix.dm.dependencymanager.add(dependencymanager.java:169) @ mongo.activator.init(activator.java:28) @ org.apache.felix.dm.dependencyactivatorbase.start(dependencyactivatorbase.java:76) @ org.apache.felix.framework.util.secureaction.startactivator(secureaction.java:645) @ org.apache.felix.framework.felix.activatebundle(felix.java:2154) @ org.apache.felix.framework.felix.startbundle(felix.java:2072) @ org.apache.felix.framework.bundleimpl.start(bundleimpl.java:976) @ aqute.launcher.launcher.update(launcher.java:457) @ aqute.launcher.launcher$1.run(launcher.java:194) @ java.util.timerthread.mainloop(timer.java:555) @ java.util.timerthread.run(timer.java:505)
warning: invocation of 'start' failed. (com.mongodb.mongoexception$network: read operation server localhost/127.0.0.1:27017 failed on database test_booksdb)
below code:
**api bundle** package api; public interface book { public string getbookname(); public void setbookname(string name); } package api; import java.util.list; public interface bookinventory { public void addbook(book book); public list<book> listbooks(); } **mongo bundle** package mongo; import org.codehaus.jackson.annotate.jsoncreator; import org.codehaus.jackson.annotate.jsonproperty; import api.book; public class bookmongo implements book{ private string _id; private string bookname; public bookmongo() { super(); // todo auto-generated constructor stub } @jsoncreator public bookmongo(@jsonproperty ("id") string _id, @jsonproperty ("bname") string bookname) { super(); this._id = _id; this.bookname = bookname; } @jsonproperty("id") public string get_id() { return _id; } public void set_id(string _id) { this._id = _id; } @override @jsonproperty("bname") public string getbookname() { return bookname; } @override public void setbookname(string name) { this.bookname = name; } @override public string tostring() { return "bookmongo [_id=" + _id + ", bookname=" + bookname + "]"; } } package mongo; import java.util.arraylist; import java.util.collection; import java.util.list; import net.vz.mongodb.jackson.dbcursor; import net.vz.mongodb.jackson.jacksondbcollection; import org.amdatu.mongo.mongodbservice; import org.codehaus.jackson.map.objectmapper; import org.codehaus.jackson.map.annotate.jsondeserialize; import com.mongodb.dbcollection; import api.book; import api.bookinventory; public class bookinventorymongo implements bookinventory{ private volatile mongodbservice mongodbservice; @override public void addbook(book book) { dbcollection collection = mongodbservice.getdb().getcollection("bookscoll"); jacksondbcollection<book, object> books = jacksondbcollection.wrap(collection, book.class); addbook books.save(book); } @override @jsondeserialize(contentas=bookmongo.class) public list<book> listbooks() { dbcollection collection = mongodbservice.getdb().getcollection("bookscoll"); jacksondbcollection<book, object> books = jacksondbcollection.wrap(collection, book.class); dbcursor<book> cursor = books.find(); list<book> result = new arraylist<book>(); while (cursor.hasnext()) { result.add(cursor.next()); } return result; } //the start method entry point app. public void start(){ book bm = new bookmongo("5","the walking dead"); addbook(bm); system.out.println("****attention***"); system.out.println("new book added mongo"); system.out.println(listbooks().tostring()); } } package mongo; import java.util.properties; import org.amdatu.mongo.mongodbservice; import org.apache.felix.dm.dependencyactivatorbase; import org.apache.felix.dm.dependencymanager; import org.osgi.framework.bundlecontext; import api.bookinventory; public class activator extends dependencyactivatorbase{ @override public void destroy(bundlecontext arg0, dependencymanager arg1) throws exception { // todo auto-generated method stub } @override public void init(bundlecontext arg0, dependencymanager dm) throws exception { properties props = new properties(); props.put("persistent", true); dm.add(createcomponent() .setinterface(bookinventory.class.getname(), props) .setimplementation(bookinventorymongo.class) .add(createservicedependency() .setservice(mongodbservice.class). setrequired(true))); } }
it clear me problem due impossibility of mongo-jackson-mapper read bank. cannot instantiate book.class
once interface.
unfortunately, annotating of api interfaces not option otherwise broke modularity.
in previous research trying solve it, thought mixins more suitable option here, didn't work @ all. might doing wrong. there option solve this? way, addbook
method in bookinventorymongo
works fine.
Comments
Post a Comment