Search in sources :

Example 1 with JsonpMapper

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());
}
Also used : JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonpMapper(org.opensearch.client.json.JsonpMapper) StringReader(java.io.StringReader) JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonString(jakarta.json.JsonString) JsonData(org.opensearch.client.json.JsonData) JsonParser(jakarta.json.stream.JsonParser) Test(org.junit.Test)

Example 2 with JsonpMapper

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);
}
Also used : JacksonJsonpMapper(org.opensearch.client.json.jackson.JacksonJsonpMapper) JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonpMapper(org.opensearch.client.json.JsonpMapper) JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) Test(org.junit.Test)

Example 3 with JsonpMapper

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());
}
Also used : StringWriter(java.io.StringWriter) JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonpMapper(org.opensearch.client.json.JsonpMapper) StringReader(java.io.StringReader) JsonGenerator(jakarta.json.stream.JsonGenerator) JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonString(jakarta.json.JsonString) JsonData(org.opensearch.client.json.JsonData) JsonParser(jakarta.json.stream.JsonParser) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 JsonpMapper (org.opensearch.client.json.JsonpMapper)3 JsonbJsonpMapper (org.opensearch.client.json.jsonb.JsonbJsonpMapper)3 JsonString (jakarta.json.JsonString)2 JsonParser (jakarta.json.stream.JsonParser)2 StringReader (java.io.StringReader)2 JsonData (org.opensearch.client.json.JsonData)2 JsonGenerator (jakarta.json.stream.JsonGenerator)1 StringWriter (java.io.StringWriter)1 JacksonJsonpMapper (org.opensearch.client.json.jackson.JacksonJsonpMapper)1