Annotation Interface NameProperty
This annotation is used by parsers to automatically set the name/key of an object when parsing structured data (e.g., JSON maps, XML elements). A common use case is when parsing a map where the map key should be stored as a property on the bean.
Requirements:
- Must be an instance method or field (not static)
- For methods: Must accept exactly one parameter (any type)
- For fields: Can be any type
- The method or field does not need to be public (will be made accessible automatically)
Can be used in the following locations:
- Bean setter methods or fields
@Rest -annotated classes and@RestOp -annotated methods when anon()value is specified
Example:
When It's Called:
- During parsing when an object is created as a value in a map/collection
- The parser automatically calls the setter or sets the field with the key/name from the parent structure
See Also:
-
Element Details
-
description
Optional description for the exposed API.- Returns:
- The annotation value.
- Since:
- 9.2.0
- Default:
- {}
-
on
Dynamically apply this annotation to the specified methods/fields.Used in conjunction with
BeanContext.Builder.applyAnnotations(Class...)to dynamically apply an annotation to an existing method/field. It is ignored when the annotation is applied directly to methods/fields.Valid patterns:
- Methods:
- Fully qualified with args:
"com.foo.MyClass.myMethod(String,int)" "com.foo.MyClass.myMethod(java.lang.String,int)" "com.foo.MyClass.myMethod()"
- Fully qualified:
"com.foo.MyClass.myMethod"
- Simple with args:
"MyClass.myMethod(String,int)" "MyClass.myMethod(java.lang.String,int)" "MyClass.myMethod()"
- Simple:
"MyClass.myMethod"
- Simple inner class:
"MyClass$Inner1$Inner2.myMethod" "Inner1$Inner2.myMethod" "Inner2.myMethod"
- Fully qualified with args:
- Fields:
- Fully qualified:
"com.foo.MyClass.myField"
- Simple:
"MyClass.myField"
- Simple inner class:
"MyClass$Inner1$Inner2.myField" "Inner1$Inner2.myField" "Inner2.myField"
- Fully qualified:
- A comma-delimited list of anything on this list.
See Also:
- Returns:
- The annotation value.
- Default:
- {}
- Methods:
-