Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bcalmac opened this issue Mar 28, 2025 · 0 comments · May be fixed by #1524
Open

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

bcalmac opened this issue Mar 28, 2025 · 0 comments · May be fixed by #1524
Labels
bug Something isn't working

Comments

@bcalmac
Copy link

bcalmac commented Mar 28, 2025

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?

@bcalmac bcalmac added bug Something isn't working untriaged labels Mar 28, 2025
@Xtansia Xtansia removed the untriaged label Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants