Search in sources :

Example 1 with JsonpSerializable

use of org.opensearch.client.json.JsonpSerializable in project opensearch-java by opensearch-project.

the class TermsQueryField method serialize.

@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
    if (_value instanceof JsonpSerializable) {
        ((JsonpSerializable) _value).serialize(generator, mapper);
    } else {
        switch(_kind) {
            case Value:
                generator.writeStartArray();
                for (FieldValue item0 : ((List<FieldValue>) this._value)) {
                    item0.serialize(generator, mapper);
                }
                generator.writeEnd();
                break;
        }
    }
}
Also used : JsonpSerializable(org.opensearch.client.json.JsonpSerializable) FieldValue(org.opensearch.client.opensearch._types.FieldValue)

Example 2 with JsonpSerializable

use of org.opensearch.client.json.JsonpSerializable in project opensearch-java by opensearch-project.

the class JsonbJsonpMapper method serialize.

@Override
public <T> void serialize(T value, JsonGenerator generator) {
    if (value instanceof JsonpSerializable) {
        ((JsonpSerializable) value).serialize(generator, this);
        return;
    }
    // JSON-B doesn't offer a way to serialize to a JSON generator, so we have to roundtrip via a string representation.
    CharArrayWriter caw = new CharArrayWriter();
    jsonb.toJson(value, caw);
    CharArrayReader car = new CharArrayReader(caw.toCharArray());
    JsonParser parser = jsonProvider.createParser(car);
    transferAll(parser, generator);
}
Also used : CharArrayReader(java.io.CharArrayReader) JsonpSerializable(org.opensearch.client.json.JsonpSerializable) CharArrayWriter(java.io.CharArrayWriter) JsonParser(jakarta.json.stream.JsonParser)

Aggregations

JsonpSerializable (org.opensearch.client.json.JsonpSerializable)2 JsonParser (jakarta.json.stream.JsonParser)1 CharArrayReader (java.io.CharArrayReader)1 CharArrayWriter (java.io.CharArrayWriter)1 FieldValue (org.opensearch.client.opensearch._types.FieldValue)1