当尝试使用Jackson序列化一个非常简单的对象时,出现异常。错误:
org.codehaus.jackson.map.JsonMappingException:未找到类MyPackage.TestA的序列化程序,也未发现创建BeanSerializer的属性(为避免异常,请禁用SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS))
下面是简单的类和要序列化的代码。
谁能告诉我为什么会出现此错误?
public class TestA {
String SomeString = "asd";
}
TestA testA = new TestA();
ObjectMapper om = new ObjectMapper();
try {
String testAString = om.writeValueAsString(testA); // error here!
TestA newTestA = om.readValue(testAString, TestA.class);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
人到中年有点甜
波斯汪
相关分类