Skip to content

fix(CON-352): correct body serialization/deserialization for analysis and attachments#39

Merged
pavanputhra merged 1 commit intomainfrom
fix/CON-352-body-serialization-deserialization
Mar 23, 2026
Merged

fix(CON-352): correct body serialization/deserialization for analysis and attachments#39
pavanputhra merged 1 commit intomainfrom
fix/CON-352-body-serialization-deserialization

Conversation

@pavanputhra
Copy link
Copy Markdown
Contributor

Summary

  • Bodies in analysis and attachments with encoding='none' were returned as JSON strings instead of their original object/array form after a save/retrieve round-trip
  • The encoding field now drives both directions: serialize on write, parse on read
  • Added src/utils/body-serialization.ts with shared serializeBody and deserializeBody helpers used across the codebase

Changes

  • src/utils/body-serialization.ts — new shared helpers for body encode/decode
  • src/db/queries.ts — apply serialize/deserialize in addAnalysis, addAttachment, and getVCon
  • src/resources/index.ts — use deserializeBody instead of ad-hoc type check
  • src/config/tenant-config.ts — use encoding field to decide how to interpret body
  • src/utils/validation.ts — handle body already being a parsed object
  • src/types/vcon.ts — type body as unknown to allow objects, arrays, and strings

Test plan

  • POST a vCon with analysis[].body as a JSON object and encoding: "none" — GET should return the body as an object, not a string
  • Same for attachments[].body
  • Bodies with encoding: "json" should remain as strings on retrieval
  • Bodies with encoding: "base64url" should remain as strings on retrieval

Fixes CON-352

🤖 Generated with Claude Code

… and attachments

Bodies stored in the TEXT column with encoding='none' were returned as JSON strings
instead of their original object/array form. The fix uses the encoding field to drive
both directions: stringify on write when encoding is 'none' or unset and body is not
already a string; parse on read under the same condition.

- Add src/utils/body-serialization.ts with serializeBody and deserializeBody helpers
- Apply serialization in queries.ts addAnalysis and addAttachment
- Apply deserialization in queries.ts getVCon for analysis and attachment rows
- Use deserializeBody in resources/index.ts and encoding-aware logic in tenant-config.ts
- Update Analysis and Attachment types: body typed as unknown to allow objects and arrays

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pavanputhra pavanputhra merged commit a9b6285 into main Mar 23, 2026
1 of 3 checks passed
@pavanputhra pavanputhra deleted the fix/CON-352-body-serialization-deserialization branch March 23, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant