您好我正在尝试使用杰克逊序列化和反序列化具有受保护构造函数的类(SimpleExpression)。当我使用 gson 时,我对此没有任何问题,但杰克逊似乎无法处理受保护的构造函数。我尝试使用 mixin-annotations 但没有奏效。序列化工作没有任何问题。杰克逊投掷:
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type
有什么帮助吗?我的代码:
private static SimpleExpression create(String json) throws JsonParseException, JsonMappingException, IOException
{
ObjectMapper mapper = new ObjectMapper().setVisibility(PropertyAccessor.ALL, Visibility.ANY);
SimpleExpression sp = null;
sp = mapper.readValue(json, SimpleExpression.class);
return sp;
}
SimpleExpression 类,我省略了 getter 和 setter。
public class SimpleExpression implements Criterion
{
private static final long serialVersionUID = 1L;
private final String propertyName;
private final Object value;
private boolean ignoreCase;
private final String op;
private final String type;
protected SimpleExpression(String propertyName, Object value, String op)
{
this.propertyName = propertyName;
this.value = value;
this.op = op;
this.type = value.getClass().getName();
}
protected SimpleExpression(String propertyName, Object value, String op, boolean ignoreCase)
{
this.propertyName = propertyName;
this.value = value;
this.ignoreCase = ignoreCase;
this.op = op;
this.type = value.getClass().getName();
}
}