opensearch-project / opensearch-project/opensearch-java

[BUG] Minimal IndexRequest fails to serialize to JSON

Open
#1,503 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
165
Forks
250
Avg merge
1d 18h
Merged PRs (30d)
26

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal JUnit 5 reproduction in the issue and trace the reported path through client/json/JsonpUtils.java, opensearch/core/IndexRequest.java, and client/json/PlainJsonSerializable.java. Confirm the behavior with Java 21 and opensearch-java 2.22.0; done means the shown IndexRequest.toJsonString() call returns JSON without JsonException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.