Skip to content

Add Automatic Nested Object Mapping (Embedded Maps) #48

@j-d-ha

Description

@j-d-ha

Priority: P1 - Critical
Tier: 2 - Single-Table Support
Effort: Large (12-20 hours)

Already In Codebase

  • No nested-object mapping exists today. The generator only supports scalar/enum-like mappings (plus custom methods).
  • The generated FromItem currently uses an object initializer: src/LayeredCraft.DynamoMapper.Generators/Templates/Mapper.scriban.

Goal

Support automatic recursive mapping of complex CLR types as embedded DynamoDB maps (AttributeValue.M).

This story is intentionally separate from collection mapping (lists/maps/sets).

Scope

  • If a property type is not a supported scalar/enum and is not a supported collection shape, treat it as a nested object.
  • Serialize nested objects to AttributeValue { M = ... }.
  • Deserialize nested objects from AttributeValue.M.

Implementation notes

  • Implement recursion in the generator: for each nested complex type encountered, generate mapping code for its members using the same rules.
  • Ensure naming convention conversion is applied at each level (DynamoNamingConvention conversion already exists).
  • Respect [DynamoIgnore] and [DynamoField(AttributeName=...)] at each mapped type.
  • Add cycle detection:
    • If type graph contains a cycle (A -> B -> A), emit a diagnostic and do not generate mapping.

Diagnostics

  • Unsupported nested member type
  • Missing map (M) when expected
  • Cycle detected in nested object graph

Tests

Add verify tests in test/LayeredCraft.DynamoMapper.Generators.Tests/ covering:

  • One-level nesting
  • Multi-level nesting
  • Nesting + naming convention changes
  • Nesting + ignore/field overrides
  • Cycle detection diagnostic

Acceptance criteria

  • Nested complex properties serialize/deserialize as embedded maps.
  • Overrides (convention, ignore, field name override) are honored inside nested objects.
  • Cycles are detected and reported via diagnostics.
  • Snapshot tests cover positive and negative scenarios.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions