Add per-field serialization inclusion support for @StoredAsJson#122
Add per-field serialization inclusion support for @StoredAsJson#122
Conversation
Allow @JsonInclude annotation on @StoredAsJson fields to control serialization inclusion for the nested JSON content only. This enables use cases like excluding empty collections from nested JSON while preserving the default ALWAYS behavior for top-level fields (required for proper DB column binding). The implementation creates a cached mapper copy with the standard JacksonAnnotationIntrospector (removing RosettaAnnotationIntrospector's ALWAYS override) when @JsonInclude is present on the field. Usage: @StoredAsJson @JsonInclude(Include.NON_EMPTY) InnerBean inner; // Empty collections excluded from nested JSON Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Do you have more info on why this matters? Is it just an optimization of storage space? Normally I would expect that as long as |
|
the primary reason is readability, very annoying to scan db rows in the cli with all the excess keys, but you could also make a case for storage size, performance benefits, especially when dealing with large, sparse json objects. i'm assuming these are the reasons these annotations exist to begin with, i won't even argue about whether this should be the default for json objects stored in mysql (although I would) but it seems like if you explicitly want this to work for a specific field, it should work, which it doesn't currently. |
|
The idea definitely makes sense, but I'm skeptical of the implementation on this branch. I think what we're looking for is to have the stored-as-json serializers maintain a single extra We'll need to do more extensive internal testing as people frequently rely on very subtle Jackson/Rosetta interactions (often unintentionally) |
Allow @JsonInclude annotation on @StoredAsJson fields to control serialization inclusion for the nested JSON content only.
This enables use cases like excluding empty collections from nested JSON while preserving the default ALWAYS behavior for top-level fields (required for proper DB column binding).
The implementation creates a cached mapper copy with the standard JacksonAnnotationIntrospector (removing RosettaAnnotationIntrospector's ALWAYS override) when @JsonInclude is present on the field.
Usage:
@StoredAsJson
@JsonInclude(Include.NON_EMPTY)
InnerBean inner; // Empty collections excluded from nested JSON