Make JSON assertions more strict

This commit is contained in:
Stephane Nicoll
2022-04-11 16:36:04 +02:00
parent f65136dd68
commit 10dc10dbf9
6 changed files with 19 additions and 9 deletions

View File

@@ -46,7 +46,7 @@ class ResourceHintsWriter {
public void write(BasicJsonWriter writer, ResourceHints hints) {
Map<String, Object> attributes = new LinkedHashMap<>();
attributes.put("resources", toAttributes(hints));
addIfNotEmpty(attributes, "resources", toAttributes(hints));
handleResourceBundles(attributes, hints.resourceBundles());
writer.writeObject(attributes);
}
@@ -81,7 +81,17 @@ class ResourceHintsWriter {
}
private void addIfNotEmpty(Map<String, Object> attributes, String name, @Nullable Object value) {
if (value != null && (value instanceof Collection<?> collection && !collection.isEmpty())) {
if (value instanceof Collection<?> collection) {
if (!collection.isEmpty()) {
attributes.put(name, value);
}
}
else if (value instanceof Map<?, ?> map) {
if (!map.isEmpty()) {
attributes.put(name, value);
}
}
else if (value != null) {
attributes.put(name, value);
}
}