Skip to content

Commit 194bbc4

Browse files
committed
#479 Move RETURN_NULL constant from MapperImpl to LeafValueHandler
1 parent 1ba1aa8 commit 194bbc4

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/main/java/ch/jalu/configme/beanmapper/MapperImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
*/
6767
public class MapperImpl implements Mapper {
6868

69-
/** Marker object to signal that null is meant to be used as value. */
70-
public static final Object RETURN_NULL = new Object();
71-
7269
// ---------
7370
// Fields and general configurable methods
7471
// ---------
@@ -159,12 +156,12 @@ public MapperImpl(@NotNull BeanDefinitionService beanDefinitionService,
159156

160157
/**
161158
* Handles values of types which need special handling (such as Optional). Null means the value is not
162-
* a special type and that the export value should be built differently. Use {@link #RETURN_NULL} to
159+
* a special type and that the export value should be built differently. Use {@link LeafValueHandler#RETURN_NULL} to
163160
* signal that null should be used as the export value of the provided value.
164161
*
165162
* @param value the value to convert
166163
* @param exportContext export context
167-
* @return the export value to use or {@link #RETURN_NULL}, or null if not applicable
164+
* @return the export value to use or {@link LeafValueHandler#RETURN_NULL}, or null if not applicable
168165
*/
169166
protected @Nullable Object createExportValueForSpecialTypes(@Nullable Object value,
170167
@NotNull ExportContext exportContext) {
@@ -192,14 +189,14 @@ public MapperImpl(@NotNull BeanDefinitionService beanDefinitionService,
192189
Optional<?> optional = (Optional<?>) value;
193190
return optional
194191
.map(v -> toExportValue(v, exportContext.createChildContext(OPTIONAL_SPECIFIER)))
195-
.orElse(RETURN_NULL);
192+
.orElse(LeafValueHandler.RETURN_NULL);
196193
}
197194

198195
return null;
199196
}
200197

201198
protected static @Nullable Object unwrapReturnNull(@Nullable Object o) {
202-
return o == RETURN_NULL ? null : o;
199+
return o == LeafValueHandler.RETURN_NULL ? null : o;
203200
}
204201

205202
// ---------

src/main/java/ch/jalu/configme/beanmapper/leafvaluehandler/LeafValueHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
public interface LeafValueHandler {
2222

23+
/** Marker object to signal that null is meant to be used as value. */
24+
Object RETURN_NULL = new Object();
25+
2326
/**
2427
* Converts the given value to the target type (as defined by the mapping context), if supported. Otherwise,
2528
* null is returned. If a value is returned, its type is guaranteed to match the target type.
@@ -33,6 +36,8 @@ public interface LeafValueHandler {
3336
/**
3437
* Converts the value of a property to a value suitable for exporting. This method converts the opposite
3538
* way of {@link #convert}. Null is returned if this leaf value handler does not support the object's type.
39+
* If the leaf value handler determines that {@code null} should be used as export value, then {@link #RETURN_NULL}
40+
* is returned, which the caller needs to unwrap to {@code null}.
3641
*
3742
* @param value the value to convert
3843
* @param exportContext the export context (usually not needed)

src/main/java/ch/jalu/configme/beanmapper/leafvaluehandler/MapperLeafType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface MapperLeafType {
3030
* when {@link ch.jalu.configme.beanmapper.MapperImpl#toExportValue(Object)} is called.
3131
* Returns null if the leaf value handler cannot handle the value.
3232
* <p>
33-
* Return {@link ch.jalu.configme.beanmapper.MapperImpl#RETURN_NULL} to signal that null should be used
33+
* Return {@link LeafValueHandler#RETURN_NULL} to signal that null should be used
3434
* as the export value (returning {@code null} itself means this leaf value handler cannot handle it).
3535
*
3636
* @param value the value to convert to an export value, if possible

0 commit comments

Comments
 (0)