Add a StrictTypeIdResolver which would throw an exception if type is not in the predefined json subtype list. Use it in DimensionSchema.#18565
Conversation
StrictTypeIdResolver which would throw an exception if type is not in the predefined json subtype list. Use it in DimensionSchema.
There was a problem hiding this comment.
Pull Request Overview
This PR adds strict type validation for JSON deserialization of DimensionSchema by introducing a custom StrictTypeIdResolver that throws exceptions for unknown types while preserving default behavior for missing types.
- Implemented
StrictTypeIdResolverto enforce strict validation of JSON type discriminators - Modified
DimensionSchemato use the new strict type resolver instead of default Jackson behavior - Added comprehensive tests for both invalid type handling and default type fallback scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| StrictTypeIdResolver.java | New custom type resolver that validates type IDs against registered subtypes |
| DimensionSchema.java | Updated to use StrictTypeIdResolver with enhanced documentation |
| DimensionSchemaTest.java | Added tests for strict type validation and default type behavior |
| StringDimensionSchemaTest.java | Removed explicit type from test JSON to verify default behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private Map<String, Class<?>> typeMap; | ||
| private JavaType baseType; |
There was a problem hiding this comment.
The typeMap field is not thread-safe and could cause issues in concurrent environments. Consider using ConcurrentHashMap or making the field volatile with proper synchronization in ensureTypeMap().
There was a problem hiding this comment.
hmmm, do we actually need to look into thread safety requirements here? I'm unfamiliar with this exact area but this comment plus a quick query of an ai agent does make me wonder if thread safety is necessary.
There was a problem hiding this comment.
actually rewrite the pr to use a builder class, PTAL!
capistrant
left a comment
There was a problem hiding this comment.
one nit for you to consider if you you want to change
requested copilot review as well. I don't think either is legit blocker
I want us to double check on any thread safety requirements with the new custom @JsonTypeIdResolver
|
Would this break existing specs that were persisted with an invalid |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| StrictTypeIdResolver() | ||
| { | ||
| // Required default constructor for Jackson, the instance is never used |
There was a problem hiding this comment.
The comment states 'the instance is never used' but this may be misleading. Jackson may instantiate this constructor for reflection purposes. Consider clarifying that this constructor creates an unusable instance that should not be used for actual resolution.
| // Required default constructor for Jackson, the instance is never used | |
| // Required default constructor for Jackson's reflective instantiation. | |
| // This creates an unusable instance that should not be used for actual resolution. |
If the |
There was a problem hiding this comment.
@cecemei this is all just ingestion spec related, correct? So if users had been submitting specs in the past with invalid types, it would quietly default to string. But with your new behavior they will get an error? So to a user, this appears to be a breaking change, but really we are just fixing undesirable behavior? I think a release note section in the PR description should be created to specify how exactly the behavior is changing and what a user should do about it to fix (point them to the valid types?).
…nsionSchemaTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
True, added a release entry. |
Description
Add a
StrictTypeIdResolverwhich would throw an exception iftypeis not in the predefined json subtype list. Use it inDimensionSchema.Key changed/added classes in this PR
StrictTypeIdResolverDimensionSchemaDimensionSchemaTestRelease note:
At ingestion time, dimension schemas are now strictly validated against allowed types. Previously an invalid type would fall back to string dimension, now such values are rejected. Users must specify
typeas one of the allowed types. Omitting type still defaults to string, preserving backward compatibility.This PR has: