use of org.opensearch.client.json.JsonpMapper 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.JsonpMapper 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);
}
use of org.opensearch.client.json.JsonpMapper in project opensearch-java by opensearch-project.
the class JsonDataTest method testSerialize.
@Test
public void testSerialize() {
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));
JsonpMapperTest.SomeClass sc = mapper.deserialize(parser, JsonpMapperTest.SomeClass.class);
assertEquals("foo", sc.getStringValue());
assertEquals(1, sc.getChildren().size());
assertEquals(2, sc.getChildren().get(0).getIntValue());
// All good
JsonData data = JsonData.of(sc);
StringWriter sw = new StringWriter();
JsonGenerator generator = mapper.jsonProvider().createGenerator(sw);
data.serialize(generator, mapper);
generator.close();
assertEquals(json, sw.toString());
}
Aggregations