Discussed in https://github.com/FasterXML/jackson-databind/discussions/5230
Originally posted by **tsegall** July 22, 2025
I get the following exception in Jackson 3 (rc6)(the same program works in Jackson 2)
Exception in thread "main" tools.jackson.databind.DatabindException: Cannot cast [Ljava.util.Locale; to java.util.Locale
at [Source: (String)"{"locale":"en-US","locales":["en-US"]}"; line: 1, column: 38] (through reference chain: j3bug.DateTimeParserConfig["locales"])
at tools.jackson.databind.DatabindException.wrapWithPath(DatabindException.java:111)
at tools.jackson.databind.deser.bean.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1850)
at tools.jackson.databind.deser.bean.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:534)
at tools.jackson.databind.deser.bean.BeanDeserializer.deserialize(BeanDeserializer.java:200)
at tools.jackson.databind.deser.DeserializationContextExt.readRootValue(DeserializationContextExt.java:265)
at tools.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2688)
at tools.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1600)
at j3bug.J3bug.main(J3bug.java:15)
Caused by: java.lang.ClassCastException: Cannot cast [Ljava.util.Locale; to java.util.Locale
at java.base/java.lang.Class.cast(Class.java:3889)
at tools.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:132)
at tools.jackson.databind.deser.bean.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:532)
... 5 more
Class I am attempting to serialize is here:
package j3bug;
import java.util.Locale;
public class DateTimeParserConfig {
public Locale[] locales;
private Locale locale;
public Locale[] getLocales() {
return locales;
}
public void setLocales(final Locale... locales) {
this.locales = locales;
if (locales != null && locales.length == 1)
this.locale = this.locales[0];
}
protected void setLocale(final Locale locale) {
this.locale = locale;
}
public Locale getLocale() {
if (locale != null)
return locale;
locales = new Locale[] { Locale.getDefault() };
return locales.length == 1 ? locales[0] : null;
}
}
Driver is here:
package j3bug;
import java.util.Locale;
import tools.jackson.core.StreamReadFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
public abstract class J3bug {
public static void main(String[] args) {
ObjectMapper mapper = JsonMapper.builder().enable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION).build();
DateTimeParserConfig cfg = new DateTimeParserConfig();
String serialized = mapper.writeValueAsString(cfg);
mapper.readValue(serialized, DateTimeParserConfig.class);
}
}
Any clues appreciated.