我使用RestTemplate。exchange在我的Spring Boot应用程序中获得以下响应:
<?xml version="1.0" encoding="UTF-8"?>
<advertisers current_page="1" per_page="10" total_pages="1" total_entries="1">
<advertiser>
<id>1057343</id>
<name>SOME ADVERTISER</name>
<status>ACTIVE</status>
<created_at>2021-10-12T09:06:12Z</created_at>
<updated_at>2022-04-08T13:36:50Z</updated_at>
</advertiser>
</advertisers>
广告商。java:
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class Advertisers {
List<Advertiser> advertiser;
}
广告商java:
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class Advertiser {
String id;
String name;
String status;
}
但我有以下例外:
org.springframework.web.client.RestClientException: Error while extracting response for type [class fr.canalplus.tvseg.models.freewheel.entities.Advertisers] and content type [application/xml;charset=utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `fr.canalplus.tvseg.models.freewheel.entities.Advertiser` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('1057343'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `fr.canalplus.tvseg.models.freewheel.entities.Advertiser` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('1057343')
at [Source: (ByteArrayInputStream); line: 4, column: 16] (through reference chain: fr.canalplus.tvseg.models.freewheel.entities.Advertisers["advertiser"]->java.util.ArrayList[0])
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:120)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:1037)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:1020)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:778)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
at fr.canalplus.tvseg.services.FreeWheelService.exchange(FreeWheelService.java:102)
at fr.canalplus.tvseg.services.FreeWheelService.getCreativeAdvertiser(FreeWheelService.java:154)
at fr.canalplus.tvseg.controllers.TestController.test(TestController.java:23)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:887)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1684)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `fr.canalplus.tvseg.models.freewheel.entities.Advertiser` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('1057343'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `fr.canalplus.tvseg.models.freewheel.entities.Advertiser` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('1057343')
at [Source: (ByteArrayInputStream); line: 4, column: 16] (through reference chain: fr.canalplus.tvseg.models.freewheel.entities.Advertisers["advertiser"]->java.util.ArrayList[0])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:387)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:342)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:105)
... 58 more
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `fr.canalplus.tvseg.models.freewheel.entities.Advertiser` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('1057343')
at [Source: (ByteArrayInputStream); line: 4, column: 16] (through reference chain: fr.canalplus.tvseg.models.freewheel.entities.Advertisers["advertiser"]->java.util.ArrayList[0])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1455)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1081)
at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:371)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:323)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1408)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:176)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:166)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:290)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:371)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:164)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3521)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:376)
... 60 more
我不明白为什么id“1057343”不能反序列化。
你能帮忙吗?提前谢谢
杰克逊抛出的例外真的很误导人。
你需要告诉杰克逊你的序列
@JacksonXmlElementWrapper(useWrapping = false)
另请参阅jacksonxmlementwrapper的javadoc。使用包装。
问题内容: 使用包中的类时遇到了json解析问题,而我得到的错误是: 发生此问题的Web应用程序是使用AngularJS前端的Spring MVC应用程序,但我可以使用更小的所有Java程序来复制该问题。这是我的豆子: Shipment.java Activity.java ActivityLocation.java 地址.java 这是我可以正确映射json的代码: 调整var中的数据时,遇到了
我正在尝试使用RestTemplate(Spring Boot)读取来自rest服务的响应: 但当响应中存在错误数组时: 我不明白为什么没有构造器/工厂方法从字符串值反序列化。 谢谢
我是Spring DataJPA+REST项目的新手,我正在尝试使用OneToOne单向关系执行从reference EmployerType添加新的或编辑雇主。当我试图添加或编辑数据时,我会得到以下错误: 下面是关于这些课程的信息。 Rest控制器
我正在尝试反序列化以下JSON 在以下自定义反序列化程序的帮助下 进入以下对象结构 我得到以下错误 通用域名格式。fasterxml。杰克逊。数据绑定。exc.MismatchedInputException:无法构造OrderId的实例(尽管至少存在一个创建者):没有从字符串值反序列化的字符串参数构造函数/工厂方法({“type”:“TAKEAWAY”,“data”:{“OrderId”:“AW
当我在Spring Data REST应用程序中使用Lombok来定义复杂类型时,例如: 使用Spring Data REST控制器,例如: 我遇到了一个可怕的错误: 来自Spring Data REST使用Jackson和Book POST,例如: 当Jackson试图解析本地URI时,会发生反序列化错误,该URI应解析为单个唯一的人。如果我删除我的RepositoryRestControlle
我正在尝试反序列化以下JSON: 我已反序列化文件: 在以下对象结构中: 规则efinition.java 定义。爪哇 和JAVA 我得到了以下错误 我看到问题是因为'and-condition-1'只是一个值,我如何反序列化这些,我想知道我应该写一个自定义反序列化器(或者)有什么解决方法吗?