Skip to content
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

[BUG]JsonEnum cannot recognize uppercase during deserialization. #1390

Open
lihuimingxs opened this issue Jan 15, 2025 · 0 comments
Open

[BUG]JsonEnum cannot recognize uppercase during deserialization. #1390

lihuimingxs opened this issue Jan 15, 2025 · 0 comments
Labels
bug Something isn't working untriaged

Comments

@lihuimingxs
Copy link

lihuimingxs commented Jan 15, 2025

What is the bug?

JsonEnum deserialization employs a lookupTable, which is a Map<String, T>.

In the deserialize method, the corresponding enumeration is obtained through the method this.lookupTable.get(value).

A problem arises regarding the case sensitivity of strings:

If the value in the enumeration class is lowercase, and uppercase letters are used in the DSL, an error will be reported. However, the DSL permits the use of uppercase letters. This can be quite confusing for developers.

How can one reproduce the bug?

Taking ZerotermsQuery as an example:


@JsonpDeserializable
public enum ZeroTermsQuery implements JsonEnum {
    All("all"),
    None("none");

    private final String jsonValue;
    public static final JsonEnum.Deserializer<ZeroTermsQuery> _DESERIALIZER = new JsonEnum.Deserializer(values());

    private ZeroTermsQuery(String jsonValue) {
        this.jsonValue = jsonValue;
    }

    public String jsonValue() {
        return this.jsonValue;
    }
}

DSL:


GET test_index/_search
{
  "query": {
    "match": {
      "text": {
          "fuzziness": "AUTO",
          "auto_generate_synonyms_phrase_query": true,
          "query": "product manager",
          "zero_terms_query": "NONE",
          "fuzzy_transpositions": true,
          "boost": 1.0,
          "prefix_length": 0,
          "operator": "OR",
          "lenient": false,
          "max_expansions": 50
      }
    }
  }
}

That will be thrown JsonparsingException when executing the anti sequence method.


public T deserialize(String value, JsonParser parser) {
            T result = (JsonEnum)this.lookupTable.get(value);
            if (result == null) {
                throw new JsonParsingException("Invalid enum '" + value + "'", parser.getLocation());
            } else {
                return result;
            }
        }

What is the expected behavior?

case-insensitive.

What is your host/environment?

Operating system, version.

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Add any other context about the problem.

@lihuimingxs lihuimingxs added bug Something isn't working untriaged labels Jan 15, 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 untriaged
Projects
None yet
Development

No branches or pull requests

1 participant