java - Cannot marshall type class without a custom marshaler or @DynamoDBDocument annotation -


error: com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmappingexception: cannot marshall type class [ljava.lang.string; without custom marshaler or @dynamodbdocument annotation.

i want store data dynamodb java spring mvc rest. making post request calls method load data amazon dynamodb. here code. restcontroller:

@restcontroller public class questionresponsecontroller {  @requestmapping(value="/loadquestiontabledata",method=requestmethod.post,produces={"application/json"}) public dynamodbmapper loadquestiontabledata()   {     return loadquestiontabledata.loadquestiontabledata();   } } 

this question.java (pojo question table in dynamodb): question.java

import java.util.arrays;  import com.amazonaws.services.dynamodbv2.datamodeling.dynamodbattribute; import com.amazonaws.services.dynamodbv2.datamodeling.dynamodbhashkey; import com.amazonaws.services.dynamodbv2.datamodeling.dynamodbtable;  @dynamodbtable(tablename = "question") public class question  { private int q_id; private string text; private string[] options; private string contraint;   @dynamodbhashkey(attributename = "options") public string[] getoptions() {     return options; }  public void setoptions(string[] options) {     this.options = options; }  @dynamodbhashkey(attributename = "q_id") public int getq_id() {     return q_id; }  public void setq_id(int q_id) {     this.q_id = q_id; }  @dynamodbattribute(attributename = "text") public string gettext() {     return text; }  public void settext(string text) {     this.text = text; }  @dynamodbattribute(attributename = "contraint") public string getcontraint() {     return contraint; }  public void setcontraint(string contraint) {     this.contraint = contraint;   }   }    //along overridden tostring(), equals(), hashcode(). 

here loadquestiontabledata.java actual loading of data takes place dynamodb. loadquestiontabledata.java

public class loadquestiontabledata  {      static dynamodbmapper mapper = null;     public loadquestiontabledata() {           //constructor        }      protected static logger logger = logger.getlogger("loadquestiontabledata");  public static dynamodbmapper loadquestiontabledata() {     try     {         amazondynamodbclient client = new amazondynamodbclient(new profilecredentialsprovider());         dynamodbmapper mapper = new dynamodbmapper(client);          question item = new question();         item.setq_id(1);         item.settext(iquestionanswerdata.amquestiontext1);         item.setoptions(iquestionanswerdata.amoptionsforqn1);         item.setcontraint(iquestionanswerdata.constraintmorning);         mapper.save(item);          item = new question();         item.setq_id(2);         item.settext(iquestionanswerdata.amquestiontext2);         item.setoptions(iquestionanswerdata.amoptionsforqn2);         item.setcontraint(iquestionanswerdata.constraintmorning);         mapper.save(item);     }     catch(amazonserviceexception ase)     {         ase.printstacktrace();         ase.getmessage();      }     catch (exception e)     {         e.printstacktrace();         e.getmessage();     }     return mapper;   } }  

i have loaded questions data interface constants. iquestionanswerdata.java

public interface iquestionanswerdata  {    static string constraintmorning= "08:00";      static string amquestiontext1 ="good";     static string amoption11="okay okay";     static string amoption12 = "better";     static string amoption13 = "nice";     static string amoption14= "awsome!";     static string [] amoptionsforqn1 = new string[]{amoption11,amoption12,amoption13,amoption14};      static string amquestiontext2 ="how health?";     string amoption21="i to!";     string amoption22 = "i'll in bit";     string amoption23 = "maybe later";     string amoption24= "i never!"; static string [] amoptionsforqn2 = new string[]{amoption21,amoption22,amoption23,amoption24}; } 

and getting error follows. stacktrace console.

19:03:37.345 [tomcat-http--6] debug o.s.w.s.m.m.a.requestmappinghandlermapping - returning handler method [public com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapper com.webapp.controller.questionresponsecontroller.loadquestiontabledata()] 19:03:37.345 [tomcat-http--6] debug o.s.b.f.s.defaultlistablebeanfactory - returning cached instance of singleton bean 'questionresponsecontroller' 19:03:37.399 [tomcat-http--6] debug com.amazonaws.amazonwebserviceclient - internal logging succesfully configured commons logger: true 19:03:37.418 [tomcat-http--6] debug com.amazonaws.metrics.awssdkmetrics - admin mbean registered under com.amazonaws.management:type=awssdkmetrics 19:03:37.581 [tomcat-http--6] debug c.a.internal.config.internalconfig - configuration override awssdk_config_override.json not found.  //error starts here  com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmappingexception: cannot marshall type class [ljava.lang.string; without custom marshaler or @dynamodbdocument annotation. @ com.amazonaws.services.dynamodbv2.datamodeling.conversionschemas$standarditemconverter.getobjecttomapmarshaller(conversionschemas.java:396) @ com.amazonaws.services.dynamodbv2.datamodeling.conversionschemas$standarditemconverter.augment(conversionschemas.java:325) @ com.amazonaws.services.dynamodbv2.datamodeling.conversionschemas$standarditemconverter.getmarshaller(conversionschemas.java:299) @ com.amazonaws.services.dynamodbv2.datamodeling.conversionschemas$standarditemconverter.convert(conversionschemas.java:265) @ com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapper$saveobjecthandler.execute(dynamodbmapper.java:1044) @ com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapper.save(dynamodbmapper.java:948) @ com.amazonaws.services.dynamodbv2.datamodeling.dynamodbmapper.save(dynamodbmapper.java:740) @ com.webapp.service.loadquestiontabledata.loadquestiontabledata(loadquestiontabledata.java:33) @ com.webapp.controller.questionresponsecontroller.loadquestiontabledata(questionresponsecontroller.java:16) @ 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.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:137) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:776) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:705) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:868) @ javax.servlet.http.httpservlet.service(httpservlet.java:644) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842) @ javax.servlet.http.httpservlet.service(httpservlet.java:725) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:501) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:142) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:610) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:516) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1086) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:659) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:147) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:277) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) 19:03:38.061 [tomcat-http--6] debug o.s.web.servlet.dispatcherservlet - null modelandview returned dispatcherservlet name 'dispatcher': assuming handleradapter completed request handling 19:03:38.061 [tomcat-http--6] debug o.s.web.servlet.dispatcherservlet - completed request 19:03:48.169 [finalizer] debug o.a.h.i.c.poolingclientconnectionmanager - connection manager shutting down 19:03:48.172 [finalizer] debug o.a.h.i.c.poolingclientconnectionmanager - connection manager shut down 19:03:48.180 [java-sdk-http-connection-reaper] debug c.a.http.idleconnectionreaper - reaper thread:  java.lang.interruptedexception: sleep interrupted @ java.lang.thread.sleep(native method) ~[na:1.8.0_45] @ com.amazonaws.http.idleconnectionreaper.run(idleconnectionreaper.java:112) ~[aws-java-sdk-1.9.40.jar:na] 19:03:48.180 [java-sdk-http-connection-reaper] debug c.a.http.idleconnectionreaper - shutting down reaper thread. 

kindly me resolve error can load items dynamodb. tia.

the problem might here public string[] getoptions(). instead of string[] can use set or list.

look @ examples:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/javaarbitrarydatamappinghlapi.html

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/javadeclarativetagslist.html

http://aws.amazon.com/articles/0802321832592496

they never use arrays.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -