我有一个看起来像这样的类 Diff:
public class Diff {
private String path;
private String value;
private Operation operation;
public enum Operation {
ADD, REPLACE, REMOVE
}
// getters and setters
}
我想使用以下调用创建一个 json 节点:
ObjectMapper mapper = new ObjectMapper();
mapper.valueToTree(diffObject);
如果我有这样的差异:
Diff diff = new Diff();
diff.setPath("/path");
diff.setValue("value");
diff.setOperation(Operation.REPLACE);
正在做:
mapper.valueToTree(diff);
将返回:
"{"path":"/path", "value":"value","operation":"REPLACE"}"
不过,我需要“操作”这个词只是“操作”。据说,有一种方法可以配置 ObjectMapper,当它读取“操作”时,它会将其转换为“操作”,但我不知道该怎么做。有人知道吗?