Skip to content

[BUG] Minimal IndexRequest fails to serialize to JSON #1503

@bcalmac

Description

@bcalmac

What is the bug?

IndexRequest.toJsonString() fails with JsonException.

How can one reproduce the bug?

Consider this minimal JUnit 5 test:

package opensearchtest;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import org.opensearch.client.opensearch.core.IndexRequest;

public class OpenSearchSerializationTest {
    @Test
    void indexRequestToJson() {
        IndexRequest<Object> indexRequest = IndexRequest.of(i -> i
                .index("index")
                .document("document"));
        assertNotNull(indexRequest.toJsonString());
    }
}

It fails with:

jakarta.json.JsonException: Cannot find a serializer for type java.lang.String. Consider using a full-featured JsonpMapper.
	at org.opensearch.client.json.JsonpUtils$1.serialize(JsonpUtils.java:84)
	at org.opensearch.client.json.JsonpUtils.serialize(JsonpUtils.java:158)
	at org.opensearch.client.opensearch.core.IndexRequest.serialize(IndexRequest.java:288)
	at org.opensearch.client.json.PlainJsonSerializable.toJsonString(PlainJsonSerializable.java:29)
	at opensearchtest.OpenSearchSerializationTest.indexRequestToJson(OpenSearchSerializationTest.java:16)

What is your host/environment?

Java 21, opensearch-java 2.22.0

Do you have any additional context?

This is an isolated test, but in the context of our application we use toJsonString() to log the content of various requests and responses. I can probably work around with a custom serialization utility, but I was expecting this to "just work". Why expose it otherwise?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions