Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ public static <T> void setEmptyValue(String strValue, Field field, T obj)
throw new IllegalArgumentException(
format("unsupported field-type %s for %s", field.getType(), field.getName()));
}
} else if (Number.class.isAssignableFrom(field.getType()) || fieldType.getClass().equals(String.class)) {
} else if (Number.class.isAssignableFrom(field.getType())) {
field.set(obj, null);
} else if (String.class.equals(field.getType())) {
field.set(obj, "");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public void testMapWithEqualsSignAndEmptyValue() {
assertEquals(config.stringStringMap.get("key2"), "");
}

@Test
public void testEmptyValuePreservesStringFieldAsEmptyString() {
Map<String, String> properties = new HashMap<>();
properties.put("name", "");

MyConfig config = new MyConfig();
config.name = "configured";
FieldParser.update(properties, config);

assertEquals(config.name, "");
}

@Test
public void testNullStrValue() throws Exception {
class TestMap {
Expand Down
Loading