私が思いついた最も強力で迅速かつ簡単な解決策は、デシリアライゼーションから取得した JsonNode ツリーをフィルタリングし、フィルタリングした結果を readerForUpdating に渡すことです。そんな感じ:
public class JacksonHelper {
public JsonNode filterBeanTree(JsonNode o, List<String> includedProperties,
List<String> excludedProperties, int maxDepth) {
JsonNode tree = o.deepCopy();
this.filterBeanTreeRecursive(tree, includedProperties, excludedProperties, maxDepth, null);
return tree;
}
private void filterBeanTreeRecursive(JsonNode tree, List<String> includedProperties,
List<String> excludedProperties, int maxDepth, String key) {
Iterator<Entry<String, JsonNode>> fieldsIter = tree.fields();
while (fieldsIter.hasNext()) {
Entry<String, JsonNode> field = fieldsIter.next();
String fullName = key == null ? field.getKey() : key + "." + field.getKey();
boolean depthOk = field.getValue().isContainerNode() && maxDepth >= 0;
boolean isIncluded = includedProperties != null
&& !includedProperties.contains(fullName);
boolean isExcluded = excludedProperties != null
&& excludedProperties.contains(fullName);
if ((!depthOk && !isIncluded) || isExcluded) {
fieldsIter.remove();
continue;
}
this.filterBeanTreeRecursive(field.getValue(), includedProperties, excludedProperties,
maxDepth - 1, fullName);
}
}
}