简体   繁体   English

com.fasterxml.jackson.databind.JsonMappingException:无法从START_OBJECT令牌中反序列化java.util.ArrayList实例

[英]com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

I have the following String and I am getting the above error. 我有以下字符串,但出现上述错误。

 {product:[{product_type_id:1, product_cat_id:1, product_type_nm:PED}, {product_type_id:2, product_cat_id:2, product_type_nm:MOBILE APP}, {product_type_id:3, product_cat_id:1, product_type_nm:MOBILE}, {product_type_id:4, product_cat_id:3, product_type_nm:PAYMENT}, {product_type_id:5, product_cat_id:5, product_type_nm:USER}, {product_type_id:6, product_cat_id:6, product_type_nm:SMS}, {product_type_id:9, product_cat_id:6, product_type_nm:EMAIL}, {product_type_id:10, product_cat_id:6, product_type_nm:TOPUP}]}

Is there anything wrong in my String. 我的琴弦有什么问题吗?

Following is the code I am using to convert. 以下是我用来转换的代码。

ObjectMapper mapper = new ObjectMapper();
             TypeFactory typeFactory = TypeFactory.defaultInstance();
            List list = mapper.readValue(new_value, typeFactory.constructCollectionType(List.class, BillingProductServiceMappingDTO.class));

Following is the exception I am getting, 以下是我得到的例外,

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
at [Source: {product:[{product_type_id:1, product_cat_id:1, product_type_nm:PED}, {product_type_id:2, product_cat_id:2, product_type_nm:MOBILE APP}, {product_type_id:3, product_cat_id:1, product_type_nm:MOBILE}, {product_type_id:4, product_cat_id:3, product_type_nm:PAYMENT}, {product_type_id:5, product_cat_id:5, product_type_nm:USER}, {product_type_id:6, product_cat_id:6, product_type_nm:SMS}, {product_type_id:9, product_cat_id:6, product_type_nm:EMAIL}, {product_type_id:10, product_cat_id:6, product_type_nm:TOPUP}]}; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:857)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:853)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:292)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:227)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:25)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2764)
at com.mkyong.common.dao.BundleDaoImpl.getDetails(BundleDaoImpl.java:64)
at com.mkyong.common.controller.HelloWorldController.handleRequestInternal(HelloWorldController.java:22)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:154)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
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.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
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:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Following is the bean I am using, 以下是我正在使用的bean,

package com.mkyong.common.dto;

 import java.io.Serializable;
 import java.util.List;

 public class BillingProductServiceMappingDTO implements Serializable{

/**
 * 
 */

private int product_type_id;
private int product_cat_id;
private int product_type_nm;
public int getProduct_type_id() {
    return product_type_id;
}
public void setProduct_type_id(int product_type_id) {
    this.product_type_id = product_type_id;
}
public int getProduct_cat_id() {
    return product_cat_id;
}
public void setProduct_cat_id(int product_cat_id) {
    this.product_cat_id = product_cat_id;
}
public int getProduct_type_nm() {
    return product_type_nm;
}
public void setProduct_type_nm(int product_type_nm) {
    this.product_type_nm = product_type_nm;
}

  }

You need to unwrap the root value ("product") to make this work. 您需要解开根值(“产品”)才能完成此工作。

Add following property to mapper object: 将以下属性添加到mapper对象:

mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

Your Json is not valid. 您的Json无效。 Try validating your json first http://jsonlint.com/ 尝试先验证您的json http://jsonlint.com/

You can try something like 您可以尝试类似

{
    "product": [{
        "product_type_id": 1,
        "product_cat_id": 1,
        "product_type_nm": "PED"
    }, {
        "product_type_id": 2,
        "product_cat_id": 2,
        "product_type_nm": "MOBILE APP"
    }, {
        "product_type_id": 3,
        "product_cat_id": 1,
        "product_type_nm": "MOBILE"
    }, {
        "product_type_id": 4,
        "product_cat_id": 3,
        "product_type_nm": "PAYMENT"
    }, {
        "product_type_id": 5,
        "product_cat_id": 5,
        "product_type_nm": "USER"
    }, {
        "product_type_id": 6,
        "product_cat_id": 6,
        "product_type_nm": "SMS"
    }, {
        "product_type_id": 9,
        "product_cat_id": 6,
        "product_type_nm": "EMAIL"
    }, {
        "product_type_id": 10,
        "product_cat_id": 6,
        "product_type_nm": "TOPUP"
    }]
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.fasterxml.jackson.databind.JsonMappingException:无法反序列化VALUE_NUMBER_INT令牌中的java.util.ArrayList实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_NUMBER_INT token com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化 START_OBJECT 令牌中的“java.util.ArrayList”实例 - com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token RestEasy:org.codehaus.jackson.map.JsonMappingException:无法从START_OBJECT标记(..)中反序列化java.util.ArrayList的实例 - RestEasy : org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token(..) com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY标记中反序列化TestAcceptanceCriteria的实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of TestAcceptanceCriteria out of START_ARRAY token 错误:com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY令牌中反序列化Entities.Student的实例 - Error: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of Entities.Student out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY令牌中反序列化org.springframework.data.domain.Sort的实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException:无法反序列化START_ARRAY令牌 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token JSON反序列化抛出异常 - 无法从START_OBJECT标记中反序列化java.util.ArrayList的实例 - JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token 无法从 START_OBJECT 令牌中反序列化 java.util.ArrayList 的实例 - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token sonMappingException:无法从START_OBJECT令牌中反序列化java.util.ArrayList的实例 - sonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM