1. 程式人生 > >org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r



org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.snaker.engine.model.StartModel["outputs"]->java.util.ArrayList[0]->org.snaker.engine.model.TransitionModel["source"]->org.snaker.engine.model.StartModel["outputs"])


at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:293)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:106)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:863)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:650)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:559)
at com.myflow.util.RestUtil.Rest(RestUtil.java:45)
at com.myflow.util.WorkflowUtil.callBack(WorkflowUtil.java:364)
at com.myflow.service.workflow.WorkflowService.submit(WorkflowService.java:270)
at com.myflow.service.workflow.WorkflowService$$FastClassBySpringCGLIB$$2ac6ade7.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.myflow.service.workflow.WorkflowService$$EnhancerBySpringCGLIB$$e8fc5d35.submit(<generated>)
at test.workflowTest.flowTest.submit(flowTest.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:205)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:175)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:217)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:641)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)

at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)


解決辦法:

    1.發生以上情況,RequestBody序列化出現問題,多出現在後臺接受前臺序列化資料,或者Rest介面資料上。可以對接受的資料物件進行測試,排除掉可能存在問題的屬性。在javabean中將出現問題的屬性的get和set方法去掉前面的get和set部分即可。

   原因,javabean序列化存在侷限,當屬性內部過於複雜,序列化將會發生異常,而序列化javabean資料預設會通過get和set方法來辨別,所以去掉get和set方法就避免了該屬性被序列化。




public ProcessConfig getProcesssConfig() {
    return processsConfig;
}

public void setProcesssConfig(ProcessConfig processsConfig) {
    this.processsConfig = processsConfig;
}

public List<Task> nextTask() {
    return nextTask;
}

public void nextTask(List<Task> nextTask) {
    this.nextTask = nextTask;
}