1. What is the main purpose of the AnnotationFormatterFactory interface in Spring MVC?
Why: AnnotationFormatterFactory is used to link a custom annotation with a Formatter so that formatting rules can be applied directly on fields.
2. Which method of WebMvcConfigurer is overridden to register an AnnotationFormatterFactory?
Why: The addFormatters method provides a FormatterRegistry where you can call addFormatterForFieldAnnotation to register your factory.
3. Which method must be implemented to specify the types of fields that a custom AnnotationFormatterFactory supports?
Why: getFieldTypes() returns a Set of Class<?> representing the field types that the factory can handle.
4. What is the role of the @Target annotation on a custom formatter annotation?
Why: @Target restricts the kinds of program elements (such as fields, methods, or parameters) to which the annotation can be applied.
5. Which retention policy is required for a custom formatter annotation to be available at runtime?
Why: Spring needs to read the annotation at runtime, so the retention policy must be RUNTIME.
6. In an AnnotationFormatterFactory, which method is responsible for creating a Parser that converts a String back to the field type?
Why: getParser() returns a Parser that is used to parse a formatted string into the target object.
7. Which interface does a custom formatter typically implement when it is bound to an annotation?
Why: A custom formatter implements org.springframework.format.Formatter, which provides both print and parse methods.
8. What is the purpose of the addFormatterForFieldAnnotation method in the FormatterRegistry?
Why: addFormatterForFieldAnnotation registers the factory that will be consulted when a field annotated with the custom annotation needs formatting.
9. Which of the following is a valid use of the @Retention annotation on a custom formatter annotation?
Why: Only RetentionPolicy.RUNTIME ensures that the annotation is available via reflection at runtime, which Spring requires.
10. What does the getPrinter method of an AnnotationFormatterFactory return?
Why: getPrinter returns a Printer object whose print method is used to render the field value as a String.
11. Which annotation is used to mark a method that registers formatters in a Spring MVC configuration class?
Why: In a WebMvcConfigurer implementation, the addFormatters method is overridden (annotated with @Override) to register formatters.
12. What is the purpose of the @Target element ElementType.FIELD in a custom formatter annotation?
Why: ElementType.FIELD indicates that the annotation can be applied to field declarations.
13. Which component is responsible for applying the formatting logic when a field is annotated with a custom formatter annotation?
Why: The AnnotationFormatterFactory is the component that Spring consults to obtain the appropriate Printer or Parser for annotated fields.
14. What is the correct way to specify that a custom annotation can be used on both fields and method parameters?
Why: @Target accepts an array of ElementType values; to include both fields and parameters, you list both FIELD and PARAMETER.
15. Which method in the Formatter interface is used to convert an object into its String representation?
Why: The print method of the Formatter interface returns the formatted String for a given object.
16. What is the purpose of the getFieldTypes method in an AnnotationFormatterFactory?
Why: getFieldTypes returns a Set of Class<?> objects representing the types of fields that the factory supports.
17. Which of the following annotations is essential for a class that implements WebMvcConfigurer to enable Spring MVC configuration?
Why: @EnableWebMvc is the standard annotation to activate Spring MVC infrastructure in a @Configuration class.