-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the deserialization of SortOptions (#981)
* Fix the deserialization of SortOptions Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * add changelog Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * spotless Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> --------- Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> (cherry picked from commit e672fdc) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a067f67
commit caa3d5b
Showing
3 changed files
with
30 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
28 changes: 28 additions & 0 deletions
28
java-client/src/test/java/org/opensearch/client/opensearch/_types/SortOptionsTest.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,28 @@ | ||
package org.opensearch.client.opensearch._types; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
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.json.jackson.JacksonJsonpMapper; | ||
|
||
public class SortOptionsTest { | ||
|
||
@Test | ||
public void testSortOptions() { | ||
String jsonString = "[{\"entityId\":{\"order\":\"asc\"}}]"; | ||
StringReader reader = new StringReader(jsonString); | ||
JacksonJsonpMapper mapper = new JacksonJsonpMapper(); | ||
JsonParser parser = mapper.jsonProvider().createParser(reader); | ||
|
||
List<SortOptions> sortOptions = JsonpDeserializer.arrayDeserializer(SortOptions._DESERIALIZER).deserialize(parser, mapper); | ||
assertEquals(1, sortOptions.size()); | ||
assertEquals(SortOptions.Kind.Field, sortOptions.get(0)._kind()); | ||
FieldSort fieldSort = (FieldSort) sortOptions.get(0)._get(); | ||
assertEquals("entityId", fieldSort.field()); | ||
assertEquals(SortOrder.Asc, fieldSort.order()); | ||
} | ||
} |