Fix DbArray support Non-native JSON-backed arrays for Integer (so MySQL, Oracle, SQLServer etc) (#3893)

Without this fix, a DbArray of List<Integer> on the plaforms that do NOT natively
support it like MySQL, Oracle, SQL Server fallback to a JSON array and this didn't
support all the specific types like Integer.

This adds the appropriate element converters when reading values, including Integer, Long, floating-point, BigDecimal, date/time, and UUID types. This prevents JSON numeric values from being returned as Long for List<Integer> properties.
This commit is contained in:
Rob Bygrave
2026-10-11 21:12:27 +13:00
committed by GitHub
parent 95cf9c3ef0
commit 9ea6197dff
@@ -5,6 +5,9 @@ import io.ebean.core.type.DocPropertyType;
import io.ebean.core.type.ScalarType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.util.UUID;
/**
@@ -30,6 +33,27 @@ class PlatformArrayTypeJsonList implements PlatformArrayTypeFactory {
if (valueType.equals(UUID.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.UUID, nullable, ArrayElementConverter.UUID);
}
if (valueType.equals(Long.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.LONG, nullable, ArrayElementConverter.LONG);
}
if (valueType.equals(Integer.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.INTEGER, nullable, ArrayElementConverter.INTEGER);
}
if (valueType.equals(Double.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.DOUBLE, nullable, ArrayElementConverter.DOUBLE);
}
if (valueType.equals(Float.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.DOUBLE, nullable, ArrayElementConverter.FLOAT);
}
if (valueType.equals(BigDecimal.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.DOUBLE, nullable, ArrayElementConverter.BIG_DECIMAL);
}
if (valueType.equals(Instant.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.TEXT, nullable, ArrayElementConverter.INSTANT);
}
if (valueType.equals(LocalDate.class)) {
return new ScalarTypeJsonList.VarcharWithConverter(DocPropertyType.TEXT, nullable, ArrayElementConverter.LOCAL_DATE);
}
return new ScalarTypeJsonList(java.sql.Types.VARCHAR, JsonStorage.VARCHAR, docType(valueType), nullable, MutationDetection.DEFAULT);
}