-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2278 - Move null to empty json collections check to BeanPropertyJson…
…Basic
- Loading branch information
Showing
9 changed files
with
85 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyJsonBasic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.ebeaninternal.server.deploy; | ||
|
||
import io.ebean.bean.EntityBean; | ||
import io.ebean.core.type.DataReader; | ||
import io.ebean.text.TextException; | ||
import io.ebeaninternal.server.deploy.meta.DeployBeanProperty; | ||
|
||
import javax.persistence.PersistenceException; | ||
import java.sql.SQLException; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
/** | ||
* A DbJson property that does not use Jackson ObjectMapper. | ||
*/ | ||
public class BeanPropertyJsonBasic extends BeanProperty { | ||
|
||
public BeanPropertyJsonBasic(BeanDescriptor<?> descriptor, DeployBeanProperty deploy) { | ||
super(descriptor, deploy); | ||
} | ||
|
||
protected BeanPropertyJsonBasic(BeanProperty source, BeanPropertyOverride override) { | ||
super(source, override); | ||
} | ||
|
||
@Override | ||
public BeanProperty override(BeanPropertyOverride override) { | ||
return new BeanPropertyJsonBasic(this, override); | ||
} | ||
|
||
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; | ||
} | ||
|
||
@Override | ||
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); | ||
} | ||
return value; | ||
} catch (TextException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new PersistenceException("Error readSet on " + descriptor + "." + name, e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters