org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of com.organisation.online.myService.common.model.Payload, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
at [Source: java.io.PushbackInputStream@6064493f; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.organisation.onlinebank.myService.common.model.Payload, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
at [Source: java.io.PushbackInputStream@6064493f; line: 1, column: 1]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:240)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:225)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:201)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:150)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:160)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:65)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:167)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:155)
at com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.performRequest(MockMvcRequestSenderImpl.java:174)
at com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.sendRequest(MockMvcRequestSenderImpl.java:404)
at com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.post(MockMvcRequestSenderImpl.java:590)
at com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.post(MockMvcRequestSenderImpl.java:79)
at com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSpecificationImpl.post(MockMvcRequestSpecificationImpl.java:752)
at com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSpecificationImpl.post(MockMvcRequestSpecificationImpl.java:66)
at org.springframework.cloud.contract.verifier.tests.ContractVerifierTest.validate_should_Create_post_Request(ContractVerifierTest.java:25)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
expected:<[2]00> but was:<[4]00>
Expected :200
Actual :400
<Click to see difference>
org.junit.ComparisonFailure: expected:<[2]00> but was:<[4]00>
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at org.springframework.cloud.contract.verifier.tests.ContractVerifierTest.validate_should_Create_post_Request(ContractVerifierTest.java:28)
我使用spring Framework的MappingJackson2HttpMessageConverter
反序列化该对象。下面是我的实现代码。
用下面的方法编写一个静态类。
public class MappingJacksonFactory {
public static MappingJackson2HttpMessageConverter create() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = converter.getObjectMapper();
objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
objectMapper.enable(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN);
SimpleModule module = new TypeModuleFactory();
objectMapper.registerModule(module);
return converter;
}
}
在setMessageConverter()
方法转换器中使用上述代码。
RestAssuredMockMvc.standaloneSetup(MockMvcBuilders.standaloneSetup(new yourController()))
.setMessageConverters(MappingJacksonFactory.create());
我正试图根据以下代码发出post请求: 在Postman,此请求工作正常,不需要身份验证,无需登录名、密码或令牌即可工作。但是,上面的代码不起作用。 日志控制台的一部分如下: 我无法粘贴整个stacktrace,因为stackoverflow平台不允许。
这是我的控制器: 这是我的配置: 这是类别类: 如果我尝试发送内容类型为application/json和以下正文的post请求: {“id”:8,“title”:“Паа”、“engTitle”:“Pizza”、“description”:null,“menuItems”:[{“id”:4,“title”:“Паааааааааааа”和“engTitle”:“Pepperoni”、“price
我目前正在做一个项目,我需要向spring发送一个POST请求。我已经找了好几个小时的解决方案,但没有找到一个可行的。当我开发该部件时,请求起了作用。问题是,在创建一些新功能(另一个控制器中有两个新endpoint)后,用于创建或更新实体的POST请求停止工作,而不会更改特定区域中的代码。 控制器: 最初,关于消费和生产的部分不在那里,我尝试了它,因为在其他帖子上看到了它,但对情况没有帮助。 传感
我可以在POST请求时发送对象列表作为响应,并在VueJs客户端中接收它 但是当我尝试用自定义类响应时(我甚至在请求映射注释中添加了) 在axios的帮助下发送VueJs端请求。邮递 Vue用户界面客户端接收 为什么我可以用对象列表响应而不能用POJO响应,以及如何解决这个问题?非常感谢。 PS.项目依赖于jackson-数据库v2.8.2和Spring v4.3.1
我正在尝试将Spring Cloud合同合并到现有项目中。我在REST方面取得了一些成功,但我正在努力设置消息端。 到目前为止,我已经在producer上建立了一个契约,它确实在target/generated test sources/contracts中生成了一个测试。我还为测试设置了一个基类。 我无法克服这个错误: 2017-09-08 17:10:51.759错误 - --[]- [ 主]
请求方式: "|3|2|url,content|\r" 参数: url 设置Post请求的url链接 content post请求的数据 返回值: "|3|code|data|\r" 参数: code http请求返回的成功或者错误码 成功:code = 200 获取数据失败:code = -1 http请求字段错误:code = 1 data http请求返回的数据 Arduino样例: sof