File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
objectbox-java-api/src/main/java/io/objectbox/annotation
objectbox-java/src/main/java/io/objectbox/converter Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package io .objectbox .annotation ;
2+
3+ import java .lang .annotation .ElementType ;
4+ import java .lang .annotation .Retention ;
5+ import java .lang .annotation .RetentionPolicy ;
6+ import java .lang .annotation .Target ;
7+
8+ /**
9+ * Defines the Java code of the default value to use for a property, when getting an existing entity and the database
10+ * value for the property is null.
11+ * <p>
12+ * Currently only {@code @DefaultValue("")} is supported.
13+ */
14+ @ Retention (RetentionPolicy .CLASS )
15+ @ Target ({ElementType .FIELD })
16+ public @interface DefaultValue {
17+ String value ();
18+ }
Original file line number Diff line number Diff line change 1+ package io .objectbox .converter ;
2+
3+ import javax .annotation .Nullable ;
4+
5+ /**
6+ * Used as a converter if a property is annotated with {@link io.objectbox.annotation.DefaultValue @DefaultValue("")}.
7+ */
8+ public class NullToEmptyStringConverter implements PropertyConverter <String , String > {
9+
10+ @ Override
11+ public String convertToDatabaseValue (String entityProperty ) {
12+ return entityProperty ;
13+ }
14+
15+ @ Override
16+ public String convertToEntityProperty (@ Nullable String databaseValue ) {
17+ if (databaseValue == null ) {
18+ return "" ;
19+ }
20+ return databaseValue ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments