-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changes to allow nulls in arrays Signed-off-by: Karthik Subramanian <ksubramanian@scholastic.com> * changes to allow nulls in arrays Signed-off-by: Karthik Subramanian <ksubramanian@scholastic.com> * updated changelog with correct PR Signed-off-by: Karthik Subramanian <ksubramanian@scholastic.com> * SpotlessJavaCheck violations fixed Signed-off-by: Karthik Subramanian <ksubramanian@scholastic.com> --------- Signed-off-by: Karthik Subramanian <ksubramanian@scholastic.com> Co-authored-by: Karthik Subramanian <ksubramanian@scholastic.com> (cherry picked from commit de8c2a9) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ff3916c
commit bae7ffe
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...client/src/test/java/org/opensearch/client/opensearch/json/JsonpDeserializerBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.opensearch.client.opensearch.json; | ||
|
||
import jakarta.json.stream.JsonParser; | ||
import java.io.StringReader; | ||
import java.util.List; | ||
import org.junit.Test; | ||
import org.opensearch.client.json.JsonpDeserializer; | ||
import org.opensearch.client.opensearch._types.FieldValue; | ||
import org.opensearch.client.opensearch.model.ModelTestCase; | ||
|
||
public class JsonpDeserializerBaseTest extends ModelTestCase { | ||
|
||
@Test | ||
public void testNullArrayItem() { | ||
|
||
String json = "[\"a\", null, \"c\"]"; | ||
|
||
// Types that don't accept null events should end up as null values in the list | ||
{ | ||
JsonpDeserializer<String> stringDeser = JsonpDeserializer.stringDeserializer(); | ||
assertFalse(stringDeser.accepts(JsonParser.Event.VALUE_NULL)); | ||
|
||
JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json)); | ||
|
||
List<String> stringList = JsonpDeserializer.arrayDeserializer(stringDeser).deserialize(parser, mapper); | ||
assertEquals("a", stringList.get(0)); | ||
assertNull(stringList.get(1)); | ||
assertEquals("c", stringList.get(2)); | ||
} | ||
|
||
// Types that do accept null events should end up as their null representation | ||
{ | ||
assertTrue(FieldValue._DESERIALIZER.accepts(JsonParser.Event.VALUE_NULL)); | ||
|
||
JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json)); | ||
List<FieldValue> valueList = JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER).deserialize(parser, mapper); | ||
|
||
assertEquals("a", valueList.get(0)._get()); | ||
assertTrue(valueList.get(1).isNull()); | ||
assertEquals("c", valueList.get(2)._get()); | ||
} | ||
} | ||
} |