我必须将带有反冲格式的JSON从MySQL数据转换为普通的Json。
我尝试执行以下代码时出现"{"billing_street_address":"","billing_street_address_2":"","billing_city_town":"","billing_state_province":"","billing_country":"","billing_postal_code":"","shipping_street_address":"7047 N Ashland Blvd","shipping_street_address_2":"","shipping_city_town":"Chicago","shipping_state_province":"IL","shipping_country"}"
com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.ctela.jasper.pojo.api.Dkpi] from String value ('{'); no single-String constructor/factory method
at [Source: "{"billing_street_address":"","billing_street_address_2":"","billing_city_town":"","billing_state_province":"","billing_country":"","billing_postal_code":"","shipping_street_address":"7047 N Ashland Blvd","shipping_street_address_2":"","shipping_city_town":"Chicago","shipping_state_province":"IL","shipping_country":"US"}"; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:843)
at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:277)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:284)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1150)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:153)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:144)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3564)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2580)
at com.ctela.jasper.service.ReferralInfoFormServiceImpl.getReferralFormDataByOperator(ReferralInfoFormServiceImpl.java:137)
at com.ctela.jasper.web.controller.JasperFormController.refRequestCommon(JasperFormController.java:87)
at com.ctela.jasper.web.controller.JasperFormController.referralRequest(JasperFormController.java:66)
at com.ctela.jasper.controller.FormController.referralRequest(FormController.java:39)
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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at com.ctela.jasper.configuration.web.filter.TimezoneStateFilter.doFilterInternal(TimezoneStateFilter.java:42)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.ctela.jasper.configuration.web.filter.UserStateFilter.doFilterInternal(UserStateFilter.java:33)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.ctela.jasper.configuration.web.filter.OrderStateFilter.doFilterInternal(OrderStateFilter.java:33)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.ctela.jasper.configuration.web.filter.OperatorStateFilter.doFilterInternal(OperatorStateFilter.java:43)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.ctela.jasper.configuration.web.filter.JasperRequestFilter.doFilterInternal(JasperRequestFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilterInternal(ResourceUrlEncodingFilter.java:51)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
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 com.ctela.jasper.configuration.web.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:86)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
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.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at com.ctela.jasper.configuration.web.filter.CsrfFilter.doFilter(CsrfFilter.java:80)
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.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at com.ctela.jasper.configuration.web.filter.EstablishSessionFilter.doFilter(EstablishSessionFilter.java:23)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:178)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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:166)
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.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
dkpilog = dkpiLogService.readDkpiById((long) 70752);
String request = dkpilog.getApiRequest();
ObjectMapper mapper = new ObjectMapper();
Dkpi readValue1 = mapper.readValue(request1, Dkpi.class);
if (readValue1!= null) {
firstName = readValue1.getUserName();
msg = readValue1.getMessageId();
}
System.out.println("firstname - " + firstName + "msg - " + msg);
\"billing_street_address\":\"\",
\"billing_street_address_2\":\"\",
\"billing_city_town\":\"\",
\"billing_state_province\":\"\",
\"billing_country\":\"\",
\"billing_postal_code\":\"\",
\"shipping_street_address\":\"7047 N Ashland Blvd\",
\"shipping_street_address_2\":\"\",
\"shipping_city_town\":\"Chicago\",
\"shipping_state_province\":\"IL\",
\"shipping_country\":\"US\",
public class Dkpi {
@JsonProperty("billing_street_address")
private String billingStreetAdd;
@JsonProperty("billing_street_address_2")
private String billingStreetAdd2;
@JsonProperty("billing_city_town")
private String billingCityTown;
@JsonProperty("billing_state_province")
private String billingStatePro;
@JsonProperty("billing_country")
private String billingCountry;
@JsonProperty("billing_postal_code")
private String billingPosCode;
@JsonProperty("shipping_street_address")
private String shippingStreetAdd;
@JsonProperty("shipping_street_address_2")
private String shippingStreetAdd2;
@JsonProperty("shipping_city_town")
private String shippingCityTown;
@JsonProperty("shipping_state_province")
private String shippingStatePro;
@JsonProperty("shipping_country")
private String shippingCountry;
public String getBillingStreetAdd() {
return billingStreetAdd;
}
public void setBillingStreetAdd(String billingStreetAdd) {
this.billingStreetAdd = billingStreetAdd;
}
public String getBillingStreetAdd2() {
return billingStreetAdd2;
}
public void setBillingStreetAdd2(String billingStreetAdd2) {
this.billingStreetAdd2 = billingStreetAdd2;
}
public String getBillingCityTown() {
return billingCityTown;
}
public void setBillingCityTown(String billingCityTown) {
this.billingCityTown = billingCityTown;
}
public String getBillingStatePro() {
return billingStatePro;
}
public void setBillingStatePro(String billingStatePro) {
this.billingStatePro = billingStatePro;
}
public String getBillingCountry() {
return billingCountry;
}
public void setBillingCountry(String billingCountry) {
this.billingCountry = billingCountry;
}
public String getBillingPosCode() {
return billingPosCode;
}
public void setBillingPosCode(String billingPosCode) {
this.billingPosCode = billingPosCode;
}
public String getShippingStreetAdd() {
return shippingStreetAdd;
}
public void setShippingStreetAdd(String shippingStreetAdd) {
this.shippingStreetAdd = shippingStreetAdd;
}
public String getShippingStreetAdd2() {
return shippingStreetAdd2;
}
public void setShippingStreetAdd2(String shippingStreetAdd2) {
this.shippingStreetAdd2 = shippingStreetAdd2;
}
public String getShippingCityTown() {
return shippingCityTown;
}
public void setShippingCityTown(String shippingCityTown) {
this.shippingCityTown = shippingCityTown;
}
public String getShippingStatePro() {
return shippingStatePro;
}
public void setShippingStatePro(String shippingStatePro) {
this.shippingStatePro = shippingStatePro;
}
public String getShippingCountry() {
return shippingCountry;
}
public void setShippingCountry(String shippingCountry) {
this.shippingCountry = shippingCountry;
}
}
我希望将Json数据转换为java对象POJO,以便将它们分别保存在各自的列中。