我需要以下解决方案。
我必须使用 objectMapper.readValue(json,clazz)在Java中解析的JSON,但出现以下问题
{
"rules": [
{
"name" : "ABCD01",
"desc" : "first abcd of the customer",
"params" : { }
}
],
"relation" : {
"AND" : ["RCH_01"]
}
}
在关系属性中,“ AND”属性是动态的,并且它取值为“ AND”或“ OR”,因此我已对其进行枚举“ Opearation”,并且[“ RCH_01”]值来自Relation类的List和我的Feature也是枚举,但反序列化时出现以下错误
线程“ main”中的异常java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 无法识别的字段“ AND”(类 com.noonpay.campaign.service.common.objects.rules.Relation),而不是 标记为可忽略(0个已知属性:))
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Operation implements Serializable {
@JsonProperty("AND")
AND,
@JsonProperty("OR")
OR;
}
和我的Relation类如下
public class Relation implements Serializable {
private Operation operation;
private List<Feature> featureList;
public Relation() {
}
public Relation(Operation operation, List<Feature> featureList) {
this.operation = operation;
this.featureList = featureList;
}
public Operation getOperation() {
return operation;
}
public List<Feature> getFeatureList() {
return featureList;
}
}
我该如何解决这个问题。