FasterXML/jackson-core

Locale deserialization fails on locales with only a language and variant

lyleschemmerling opened this issue · 2 comments

Seen on 2.15.3, tested on 2.17.0 using
openjdk 21.0.2 2024-01-16 LTS
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)

This simple test fails:

@Test
public void test() throws Exception {
  var objectMapper = new ObjectMapper();
  var locale = new Locale.Builder().setLanguage("be").setVariant("TARASK").build();

  assertEquals(locale, objectMapper.readValue(objectMapper.writeValueAsString(locale), Locale.class));
}

It's a strange Locale that I am not sure is valid but it is listed when invoking Locale.getAvailableLocales(). I have some code that iterates over all of them and ensures that we are handling them correctly via some API calls and in moving to Java 21 from 17 the tests started to fail. Ideally, the serialization to deserialization would never fail regardless of the input.

Let me know if you have more questions.

Can you provide the stacktrace? It is a real courtesy - not expecting other people to run the code to see the issue.

closing. I realized my mistake, the issue is with locale.toLanguageTag()