mirror of
https://github.com/spring-projects/spring-data-mongodb.git
synced 2026-05-03 03:34:23 +01:00
Fix null value handling in ParameterBindingJsonReader#readStringFromExtendedJson.
This commit makes sure to return null for a null parameter value avoiding a potential NPE when parsing data. In doing so we can ensure object creation is done with the intended value that may or may not lead to a downstream error eg. when trying to create an ObjectId with a null hexString. Closes: #4282 Original pull request: #4334
This commit is contained in:
committed by
Mark Paluch
parent
79c6427cc9
commit
af2076d4a5
+2
-1
@@ -1412,7 +1412,8 @@ public class ParameterBindingJsonReader extends AbstractBsonReader {
|
||||
// Spring Data Customization START
|
||||
|
||||
if (patternToken.getType() == JsonTokenType.STRING || patternToken.getType() == JsonTokenType.UNQUOTED_STRING) {
|
||||
return bindableValueFor(patternToken).getValue().toString();
|
||||
Object value = bindableValueFor(patternToken).getValue();
|
||||
return value != null ? value.toString() : null;
|
||||
}
|
||||
|
||||
throw new JsonParseException("JSON reader expected a string but found '%s'.", patternToken.getValue());
|
||||
|
||||
+8
@@ -243,6 +243,14 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
assertThat(value.getTime()).isEqualTo(1429196157626L);
|
||||
}
|
||||
|
||||
@Test // GH-4282
|
||||
public void shouldReturnNullAsSuch() {
|
||||
|
||||
String json = "{ 'value' : ObjectId(?0) }";
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> parse(json, new Object[] { null }))
|
||||
.withMessageContaining("hexString");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2418
|
||||
void shouldNotAccessSpElEvaluationContextWhenNoSpElPresentInBindableTarget() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user