Package io.github.og4dev.annotation


package io.github.og4dev.annotation
Custom annotations for controlling JSON deserialization behavior.

This package provides annotations that modify the default JSON processing behavior of the OG4Dev Spring API Response library, allowing fine-grained control over string field handling at the field level.

Available Annotations:

  • NoTrim - Disables automatic whitespace trimming for specific string fields while maintaining XSS validation

Default Behavior Without Annotations:

By default, all string fields in DTOs undergo automatic processing during JSON deserialization:

  • Whitespace Trimming: Leading and trailing spaces are removed
  • XSS Validation: HTML tags are detected and rejected
  • Null Preservation: Null values remain null (not converted to empty strings)

Use Case Example:


 public class AuthDTO {
     private String username;      // Automatically trimmed
     private String email;         // Automatically trimmed

     @NoTrim
     private String password;      // Preserves original whitespace
 }
 

Integration with Jackson:

These annotations are processed by custom Jackson deserializers registered in ApiResponseAutoConfiguration.strictJsonCustomizer(). The deserializers use Jackson's contextual deserialization mechanism (ValueDeserializer.createContextual(tools.jackson.databind.DeserializationContext, tools.jackson.databind.BeanProperty)) to detect annotations and adjust behavior accordingly.

Since:
1.2.0
Version:
1.2.0
Author:
Pasindu OG
See Also:
  • Annotation Interfaces
    Class
    Description
    Annotation to disable automatic string trimming during JSON deserialization.