发送Json并在其中获取null

时间:2014-11-22 17:21:16

标签: java json spring spring-boot retrofit

我的问题是我的Spring控制器上有这个:

@RequestMapping(value = "/test/setgamesets", method = RequestMethod.POST,consumes="application/json")
public @ResponseBody Collection<GameSet> setGameSets(@RequestBody ArrayList<GameSet> gmsets) 

我是通过改造发送的:

11-22 18:04:31.706  10130-11240/com.testing.test D/Retrofit﹕ ---> HTTP POST https://192.168.1.68:8443/test/setgamesets
11-22 18:04:31.706  10130-11240/com.testing.test D/Retrofit﹕ Authorization: Bearer d77b22b2-41e6-4774-9ed9-daa16f0c49de
11-22 18:04:31.706  10130-11240/com.testing.test D/Retrofit﹕ Content-Type: application/json
11-22 18:04:31.706  10130-11240/com.testing.test D/Retrofit﹕ Content-Length: 849
11-22 18:04:31.706  10130-11240/com.testing.test D/Retrofit﹕ [{"explanation":"I dont know why this is wrong.","title4":"MovieD","question":"Choose one of the following, which is wrong.","title3":"MovieC","title2":"MovieB","title1":"MovieA","id":1,"rate":1.0,"rates":4,"wrong":1},{"explanation":"I dont know why this is wrong.","title4":"MovieD","question":"What is wrong with the follow movies.","title3":"MovieC","title2":"MovieB","title1":"MovieA","id":2,"rate":1.0,"rates":5,"wrong":2},{"explanation":"I dont know why this is wrong.","title4":"MovieD","question":"What is wrong with the follow movies.","title3":"MovieC","title2":"MovieB","title1":"MovieA","id":3,"rate":5.0,"rates":25,"wrong":3},{"explanation":"I dont know why this is wrong.","title4":"MovieD","question":"What is wrong with the follow movies.","title3":"MovieC","title2":"MovieB","title1":"MovieA","id":4,"rate":0.0,"rates":0,"wrong":4}]
11-22 18:04:31.706  10130-11240/com.testing.test D/Retrofit﹕ ---> END HTTP (849-byte body)

对改造的回应:

11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ <--- HTTP 500 https://192.168.1.68:8443/test/setgamesets (162ms)
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Server: Apache-Coyote/1.1
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ X-Content-Type-Options: nosniff
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ X-XSS-Protection: 1; mode=block
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Cache-Control: no-cache, no-store, max-age=0, must-revalidate
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Pragma: no-cache
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Expires: 0
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Strict-Transport-Security: max-age=31536000 ; includeSubDomains
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ X-Frame-Options: DENY
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Set-Cookie: JSESSIONID=CE3FAAAA44CBB98C0030138A9C94AEFC; Path=/; Secure; HttpOnly
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ X-Application-Context: application
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Content-Type: application/json
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Transfer-Encoding: chunked
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Date: Sat, 22 Nov 2014 16:04:27 GMT
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ Connection: close
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ {"timestamp":1416672267525,"error":"Internal Server Error","status":500,"exception":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"}
11-22 18:04:31.867  10130-11240/com.androidcapstoneproject.mutibo D/Retrofit﹕ <--- END HTTP (315-byte body)

在Spring Server上,我得到了这个:

---------------------------------- 1
id: 1
question: Choose one of the following, which is wrong.
title1: MovieA
title2: null
title3: null
title4: null
wrong: 1
explanation: I dont know why this is wrong.
rate: 4.0
rates: 0
---------------------------------- 1
Hibernate: select gameset0_.id as id1_0_0_, gameset0_.explanation as explanat2_0_0_, gameset0_.question as question3_0_0_, gameset0_.rate as rate4_0_0_, gameset0_.rates as rates5_0_0_, gameset0_.title1 as title6_0_0_, gameset0_.title2 as title7_0_0_, gameset0_.title3 as title8_0_0_, gameset0_.title4 as title9_0_0_, gameset0_.wrong as wrong10_0_0_ from game_set gameset0_ where gameset0_.id=?
Hibernate: update game_set set explanation=?, question=?, rate=?, rates=?, title1=?, title2=?, title3=?, title4=?, wrong=? where id=?
2014-11-22 19:15:56.139  WARN 8352 --- [nio-8443-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1048, SQLState: 23000
2014-11-22 19:15:56.140 ERROR 8352 --- [nio-8443-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Column 'title2' cannot be null
2014-11-22 19:15:56.140  INFO 8352 --- [nio-8443-exec-1] o.h.e.j.b.internal.AbstractBatchImpl     : HHH000010: On release of batch it still contained JDBC statements
2014-11-22 19:15:56.144 ERROR 8352 --- [nio-8443-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'title2' cannot be null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
    at com.mysql.jdbc.Util.getInstance(Util.java:383)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1049)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4208)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4140)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2597)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2826)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2334)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187)
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3281)
    at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3525)
    at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:158)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:515)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:105)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy69.save(Unknown Source)
    at testing.test.main.MyController.setGameSets(MyController.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilter(WebRequestTraceFilter.java:115)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextFilterConfiguration$1.doFilterInternal(EndpointWebMvcAutoConfiguration.java:137)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:140)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter.doFilterInternal(MetricFilterAutoConfiguration.java:85)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1721)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

2014-11-22 19:15:56.148 ERROR 8352 --- [nio-8443-exec-1] o.s.b.actuate.web.BasicErrorController   : org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

我的问题是我如何在ResponseBody对象上获取null?你能指导我在哪里找我的错吗?

这是我的代码here

感谢您的关注和时间。

0 个答案:

没有答案