Skip to content
Merged
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 @@ -519,6 +519,9 @@ public static <T> T readValue(JsonNode jsonValue,
* @return converted JSON value
*/
public static BaseJsonNode writeValue(Object object) {
if (object == null) {
return (BaseJsonNode) objectMapper.nullNode();
}
return objectMapper.valueToTree(object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.node.ArrayNode;
import tools.jackson.databind.node.BaseJsonNode;
import tools.jackson.databind.node.DoubleNode;
import tools.jackson.databind.node.ObjectNode;

Expand Down Expand Up @@ -490,4 +491,11 @@ public void toFileJson() throws JacksonException {

}

@Test
public void writeValue_nullReturnsNullNode() {
BaseJsonNode result = JacksonUtils.writeValue(null);
Assert.assertTrue("Expected NullNode", result.isNull());
Assert.assertEquals(mapper.nullNode(), result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public ReactAdapterView() {
(event) -> input.setValue("set value"));
setValueButton.setId("setValueButton");

var setNullButton = new NativeButton("Set null",
(event) -> input.setValue(null));
setNullButton.setId("setNullValueButton");

var getOutput = new Span();
getOutput.setId("getOutput");

Expand All @@ -43,7 +47,7 @@ public ReactAdapterView() {
getValueButton.setId("getValueButton");

add(new Div(input, listenerOutput), new Div(setValueButton),
new Div(getValueButton, getOutput));
new Div(setNullButton), new Div(getValueButton, getOutput));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ public void validateListener() {
$(SpanElement.class).id("listenerOutput").getText());
}

@Test
public void validateSetNullState() {
open();

waitForDevServer();

$(NativeButtonElement.class).id("setNullValueButton").click();

// getPropertyString returns null for null/undefined values
String value = getAdapterElement().getPropertyString("value");
Assert.assertNull("Expected null value, not string 'null'", value);
}

private TestBenchElement getAdapterElement() {
return $("react-input").first();
}
Expand Down
Loading