@Target(value={FIELD,PARAMETER}) @Retention(value=RUNTIME) @Documented @MinMuleVersion(value="4.5.0") public @interface NullSafe
null value, even though such value is a valid
assignment on the mule DSL.
This annotation is intended to be used alongside Optional (the concept itself doesn't make sense for required
parameters). When the annotated parameter is resolved to a null value, the runtime will create a default instance of
such parameter to prevent a null variable.
This behaviour is implemented slightly different depending on the parameter type:
Collection and Map: an empty collection/map is createddefaultImplementingType.Optional Parameter fields with a default value will be assigned to
such default. E.g.:
public class HelloWorld {
@Parameter
@Optional(defaultValue="Hello world!"
private String greeting;
}
A null safe parameter of type HelloWorld would be created with the greeting field assigned to Hello world!
IllegalParameterModelDefinitionException will be
thrown by the runtime if used in parameters of such type| Modifier and Type | Optional Element and Description |
|---|---|
Class<?> |
defaultImplementingType
Declares the default
Type that will be instantiated if the NullSafe mechanism is triggered on a
non-instantiable type |
public abstract Class<?> defaultImplementingType
Type that will be instantiated if the NullSafe mechanism is triggered on a
non-instantiable typeType to be used when creating the default instanceCopyright © 2022. All rights reserved.