boolean (List<ResolvedClassType> objects) { List<Set<String>> requiredFields = new ArrayList<>(); Set<String> defaultObjFields = null; for (ResolvedClassType obj : objects) { Set<String> localRequired = getRequiredFields(obj.node); if (localRequired.isEmpty()) { if (defaultObjFields != null) { return false; } defaultObjFields = new HashSet<>(); JsonNode properties = obj.node.get("properties"); if (properties != null) { for (Iterator<String> it = properties.fieldNames(); it.hasNext(); ) { defaultObjFields.add(it.next()); } } } else { requiredFields.add(localRequired); } } for (int i = 0; i < requiredFields.size(); i++) { Set<String> a = requiredFields.get(0); if (defaultObjFields != null && defaultObjFields.stream().anyMatch(a::contains)) { return false; } for (int j = i + 1; j < requiredFields.size(); j++) { Set<String> b = requiredFields.get(1); if (a.containsAll(b) || b.containsAll(a)) { return false; } } } return true; }