我想在java 11中使用番石榴的Maps.difference来验证Json字符串中的数据,我将Json字符串映射到一个Map中。
我在打完电话后(每次都有不同的uid ):
{"uid":"31a340bc-e5ed-440c-8726-34c54dea902a","name":"Jean"}我想验证是否正确地生成了uid,并且使用如下模式命名为"Jean“:
{"uid":"*","name":"Jean"}当然,Maps.difference返回uid值的差异..。
是否可以在我的验证模式中指定通配符,以便Maps.difference不返回任何差异?
提前谢谢。
发布于 2021-10-08 10:28:35
假设你指的是番石榴的Maps.difference:是的,使用difference(left, right, valueEquivalence) overload
Maps.difference(left, right, new Equivalence<String>() {
@Override public boolean doEquivalent(String a, String b) {
return "*".equals(a) || "*".equals(b) || Objects.equals(a, b);
}
// You have to hash all strings to the same thing because you
// don't know if the current item is a "*", or its corresponding
// item is a "*". But actually it doesn't matter, because I don't
// think it's invoked in difference.
@Override public int doHash(String s) { return 0; }
});https://stackoverflow.com/questions/69494309
复制相似问题