问题描述
ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree(json); JsonNode jn = jsonNode.get("indexs");System.out.println(jn.toString());Indexs p = mapper.readValue(json, Indexs.class); org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.abc.search.vo.IndexField]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.StringReader@33a626ac; line: 1, column: 70] (through reference chain: com.abc.search.vo.Indexs["indexs"]->com.abc.search.vo.Index["indexFields"])详细问题:http://www.iteye.com/problems/94592 问题补充:IndexField 类/** * */package com.abc.search.vo;import java.io.Serializable;import java.util.Date;public class IndexField implements Serializable {private static final long serialVersionUID = 2140557360587491345L;public static final int TYPE_STRING = 1;public static final int TYPE_LONG = 2;public static final int TYPE_INT = 3;public static final String FIELD_ID = "index_id";public static final String FIELD_CREATETIME = "index_createTime";private String name;private String strValue;private long longValue;private int intValue;private int type;private boolean analyzed;private boolean highlight;public IndexField(){}public IndexField(String name, String value) {this(name, value, true, true);}public IndexField(String name, String value, boolean analyzed, boolean highlight) {this.name = name;this.strValue = value != null ? value : "";this.type = TYPE_STRING;this.analyzed = analyzed;this.highlight = highlight;}public IndexField(String name, Date value){this.name = name;this.longValue = value.getTime();this.strValue = String.valueOf(value);this.type = TYPE_LONG;this.analyzed = false;this.highlight = false;}public IndexField(String name, long value){this.name = name;this.longValue = value;this.strValue = String.valueOf(value);this.type = TYPE_LONG;this.analyzed = false;this.highlight = false;}public IndexField(String name, int value){this.name = name;this.intValue = value;this.strValue = String.valueOf(value);this.type = TYPE_INT;this.analyzed = false;this.highlight = false;}public String getName() {return name;}public int getType() {return type;}public String getStrValue() {return strValue;}public long getLongValue() {return longValue;}public int getIntValue() {return intValue;}public boolean isAnalyzed() {return analyzed;}public boolean isHighlight() {return highlight;}}
解决方案
运行了你这个IndexField,没有问题的。最好把json相关的bean都贴出来,像我上次回复你的那样,你那个json也就3个bean:IndexField、Index、Indexs(按照你的写法)
解决方案二:
IndexField 有空参构造器吗
解决方案三:
No suitable constructor found for type [simple type, class com.abc.search.vo.IndexField], 把com.abc.search.vo.IndexField的代码贴出来