mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-19 16:16:08 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user