mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2278 - Do not override empty json collections, when database value is null
This commit is contained in:
@@ -50,6 +50,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -623,9 +624,21 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
return scalarType.read(reader);
|
||||
}
|
||||
|
||||
protected Object checkForEmpty(EntityBean bean) {
|
||||
final Object value = getValue(bean);
|
||||
if (value instanceof Collection && ((Collection<?>) value).isEmpty()
|
||||
|| value instanceof Map && ((Map<?, ?>) value).isEmpty()) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object readSet(DataReader reader, EntityBean bean) throws SQLException {
|
||||
try {
|
||||
Object value = scalarType.read(reader);
|
||||
if (value == null) {
|
||||
value = checkForEmpty(bean);
|
||||
}
|
||||
if (bean != null) {
|
||||
setValue(bean, value);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,9 @@ public class BeanPropertyJsonMapper extends BeanProperty {
|
||||
public Object readSet(DataReader reader, EntityBean bean) throws SQLException {
|
||||
try {
|
||||
Object value = scalarType.read(reader);
|
||||
if (value == null) {
|
||||
value = checkForEmpty(bean);
|
||||
}
|
||||
if (bean != null) {
|
||||
setValue(bean, value);
|
||||
String json = reader.popJson();
|
||||
|
||||
Reference in New Issue
Block a user