UNOMI-952: Return HTTP 400 for malformed Item JSON in REST requests#777
Merged
Conversation
Harden ItemDeserializer to reject non-object or incomplete Item payloads with JsonMappingException, and map wrapped JSON deserialization failures to 400 instead of 500.
… handling. - Use ConcurrentHashMap for thread-safe OSGi registration/deregistration - Override getNullValue() to reject null Item tokens with JsonMappingException - Guard treeToValue() result against null to avoid silent NPE -> 500 - RuntimeExceptionMapper now returns 400 for JsonParseException root causes - Restore WARN/ERROR rationale comment; update RestExceptionMapperTest Javadoc - Expand ItemDeserializerTest: customItemType assertion, array-root rejection, numeric itemType/itemId rejection, unregisterMapping fallback coverage
- Use textValue() consistently for itemIdNode (matches itemTypeNode pattern) - describeJsonNode fallback now produces "a number/boolean/..." for grammar consistency - Add comment explaining why itemType is stripped only for registered types - Add boolean-root test to cover describeJsonNode fallback branch - Add cycle-guard comment in getRootCause() explaining it is unreachable in practice - Add MAX_MESSAGE_LENGTH cap to LogSanitizer.forLogging() to prevent log amplification
The test asserted executionCount==1 after awaiting a latch, but the task runs at a 100ms fixed rate. On a loaded CI runner the second tick could fire between the latch release and the assertEquals, causing a spurious failure. Move preDestroy() before the assertion so the scheduler is fully stopped before we read the counter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ItemDeserializerto reject non-object or incomplete Item JSON (itemType/itemIdrequired) withJsonMappingExceptioninstead ofClassCastException/ NPE.RuntimeExceptionMapperto HTTP 400 (badRequestJSON), completing the UNOMI-928 error-handling work for malformed REST payloads.ItemDeserializerTestcoverage including registered type mappings.JIRA
Test plan
mvn -pl persistence-spi test -Dtest=ItemDeserializerTestmvn -pl rest test -Dtest=RestExceptionMapperTest,LogSanitizerTestsource/targetItem (e.g.{}, string) → HTTP 400 JSON{"errorMessage":"badRequest"}