#2278 - Do not override empty json collections, when database value is null

This commit is contained in:
rbygrave
2021-07-30 22:53:51 +12:00
parent e62bb3dc6b
commit 2691221168
3 changed files with 17 additions and 2 deletions
@@ -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();