use of org.opensearch.client.json.jsonb.JsonbJsonpMapper in project opensearch-java by opensearch-project.
the class RequestEncodingTest method testParametersNotInJson.
@Test
public void testParametersNotInJson() {
// This checks that path parameters ("q") are not serialized as json
// and variant containers ser/deser
SearchRequest request = new SearchRequest.Builder().q("blah").query(b1 -> b1.type(b2 -> b2.value("foo"))).aggregations("myagg", b2 -> b2.avg(b3 -> b3.field("foo"))).build();
JsonbJsonpMapper mapper = new JsonbJsonpMapper();
String str = toJson(request, mapper);
assertEquals("{\"aggregations\":{\"myagg\":{\"avg\":{\"field\":\"foo\"}}},\"query\":{\"type\":{\"value\":\"foo\"}}}", str);
request = fromJson(str, SearchRequest.class, mapper);
assertTrue(request.query().isType());
assertEquals("foo", request.query().type().value());
assertNull(request.q());
}
use of org.opensearch.client.json.jsonb.JsonbJsonpMapper in project opensearch-java by opensearch-project.
the class JsonDataTest method testParsing.
@Test
public void testParsing() {
JsonpMapper mapper = new JsonbJsonpMapper();
String json = "{\"children\":[{\"doubleValue\":3.2,\"intValue\":2}],\"doubleValue\":2.1,\"intValue\":1," + "\"stringValue\":\"foo\"}";
JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json));
JsonData data = JsonData.from(parser, mapper);
assertEquals("foo", data.toJson().asJsonObject().getString("stringValue"));
JsonpMapperTest.SomeClass to = data.to(JsonpMapperTest.SomeClass.class);
assertEquals("foo", to.getStringValue());
}
use of org.opensearch.client.json.jsonb.JsonbJsonpMapper in project opensearch-java by opensearch-project.
the class InheritanceTest method testSerialization.
@Test
public void testSerialization() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonProvider provider = JsonProvider.provider();
FinalClass fc = new FinalClass.Builder().baseField("baseValue").childField("childValue").finalField("finalValue").build();
JsonGenerator generator = provider.createGenerator(baos);
fc.serialize(generator, new JsonbJsonpMapper());
generator.close();
String str = baos.toString();
assertEquals("{\"baseField\":\"baseValue\",\"childField\":\"childValue\",\"finalField\":\"finalValue\"}", str);
baos.reset();
ChildClass cc = new ChildClass.Builder().baseField("baseValue").childField("childValue").build();
generator = provider.createGenerator(baos);
cc.serialize(generator, new JsonbJsonpMapper());
generator.close();
str = baos.toString();
assertEquals("{\"baseField\":\"baseValue\",\"childField\":\"childValue\"}", str);
}
use of org.opensearch.client.json.jsonb.JsonbJsonpMapper in project opensearch-java by opensearch-project.
the class SomeUnionTest method testSerialization.
@Test
public void testSerialization() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonProvider provider = JsonProvider.provider();
JsonGenerator generator = provider.createGenerator(baos);
su.serialize(generator, new JsonbJsonpMapper());
generator.close();
System.out.println(baos.toString());
assertEquals(json, baos.toString());
}
use of org.opensearch.client.json.jsonb.JsonbJsonpMapper in project opensearch-java by opensearch-project.
the class JsonpMapperTest method testJsonb.
@Test
public void testJsonb() {
JsonpMapper mapper = new JsonbJsonpMapper();
testSerialize(mapper, json);
testDeserialize(mapper, json);
}
Aggregations