jackson 没有getter 时报异常org.codehaus.jackson.map.JsonMappingException的解决方法,,当一个类的所有属性都没有
分享于 点击 27829 次 点评:53
jackson 没有getter 时报异常org.codehaus.jackson.map.JsonMappingException的解决方法,,当一个类的所有属性都没有
当一个类的所有属性都没有getter时(所有属性都是public的)jackson序列化时会抛出如下异常:
org.codehaus.jackson.map.JsonMappingException: No serializer foundfor class log.LogUser and no properties discovered to create BeanSerializer(to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS)) (through reference chain:log.Log["owners"]->java.util.ArrayList[0])
解决方法为:在每个public属性上使用注解@JsonProperty。
[Java]示例代码
public class LogUser implements Serializable {@JsonPropertypublic String name;}
用户点评