Annotation Interface NullSafe
@MinMuleVersion("4.1")
@Target({FIELD,PARAMETER})
@Retention(RUNTIME)
@Documented
public @interface NullSafe
Indicates that the annotated parameter should never be assigned a Basic types: String, numbers, dates, etc, are not supported. A
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:
CollectionandMap: an empty collection/map is created- A generic Pojo: A default instance is created (default constructor required)
- An non-instantiable type: A default instance is created using the type provided as parameter in
defaultImplementingType. Any
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- Since:
- 1.0
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>Declares the defaultTypethat will be instantiated if theNullSafemechanism is triggered on a non-instantiable type
-
Element Details
-
defaultImplementingType
Class<?> defaultImplementingTypeDeclares the defaultTypethat will be instantiated if theNullSafemechanism is triggered on a non-instantiable type- Returns:
- the default
Typeto be used when creating the default instance
- Default:
- java.lang.Object.class
-