Skip to content
Snippets Groups Projects
Commit 316b4580 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] Json parser must be able to parse null value

parent 07ad2013
No related branches found
No related tags found
No related merge requests found
Pipeline #9559 passed
......@@ -123,6 +123,9 @@ public class JsonAttributeParser<T extends Object> {
final String value = matcher.group(1);
try {
if (value == null) {
return null;
}
return parseValue(value);
}
catch(NumberFormatException | UnknownFormatConversionException e) {
......
......@@ -113,4 +113,32 @@ public class JsonAttributeParserTest {
expectedJson = expectedJson.replace("\"ts\":\"" + TS_VALUE + "\",", "");
Assert.assertEquals(expectedJson, newJson);
}
@Test
public void parseNullableValue() {
// Long
{
String jsonString = "{\n" +
" \"ts\": null\n" +
"}";
// nullable = true
JsonAttributeParser<Long> tsAttribute = new JsonAttributeParser<>(PROPERTY_TS, Long.class);
Long parsedValue = tsAttribute.getValue(jsonString);
Assert.assertNull(parsedValue);
}
// String
{
String jsonString = "{\n" +
" \"id\": null\n" +
"}";
// nullable = true
JsonAttributeParser<String> idAttribute = new JsonAttributeParser<>(PROPERTY_ID, String.class);
String parsedValue = idAttribute.getValue(jsonString);
Assert.assertNull(parsedValue);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment