Skip to content

feat(data): Pydantic-aware Mapper + nested/collection recursion + @mapping decorator (v26.06.24)#50

Merged
ancongui merged 1 commit into
mainfrom
feat/mapper-pydantic-nested
Jun 7, 2026
Merged

feat(data): Pydantic-aware Mapper + nested/collection recursion + @mapping decorator (v26.06.24)#50
ancongui merged 1 commit into
mainfrom
feat/mapper-pydantic-nested

Conversation

@ancongui
Copy link
Copy Markdown
Contributor

@ancongui ancongui commented Jun 7, 2026

Summary

Wave 3 — the MapStruct ask. Per the analysis, extended the existing pyfly.data.Mapper (runtime/reflection) rather than cloning MapStruct's compile-time codegen / generated *Impl classes / expression DSL.

  • Pydantic-aware — shallow field extraction keeps nested models as live instances (previously dataclasses.asdict deep-flattened nested models to dicts, breaking nested destinations); Pydantic read via model_fields, constructed through the validating constructor.
  • Nested-model recursion — a destination field typed as another mappable model (dataclass / Pydantic) is mapped recursively.
  • Collection recursionlist/tuple/set fields of a mappable element type map element-wise.
  • Declarative @mapping@mapping(Source, Dest, rename=..., transform=..., exclude=...) registers on a module-level default_mapper, config next to the types. Exported as pyfly.data.mapping / default_mapper.

Existing Mapper API (add_mapping/map/map_list/projections) unchanged & back-compatible.

Tests

tests/data/test_mapper_nested.py (4: nested recursion, collection recursion, pydantic rename/transform, declarative decorator) + existing 16 mapper tests green.

Gates

mypy --strict (609) ✓ · ruff + ruff format ✓ · full suite 3746 passed, 1 skipped.

Bumps v26.06.23 → v26.06.24. Wave 4 (RFC 7807, multi-datasource, SpEL, Testcontainers) to follow.

Records/Lombok: no code — covered idiomatically by frozen dataclasses / Pydantic, as established.

…mapping decorator + bump v26.06.24

Spring-parity work, wave 3 (MapStruct). Extended the existing pyfly.data.Mapper
(runtime/reflection, not Java codegen):
- Pydantic-aware: shallow extraction keeps nested models as live instances (was
  dataclasses.asdict deep-flatten, which broke nested dests); pydantic read via
  model_fields + constructed through the validating constructor.
- Nested-model recursion: a dest field typed as another mappable model is mapped recursively.
- Collection recursion: list/tuple/set dest fields of a mappable element type map element-wise.
- Declarative @mapping(Source, Dest, rename=, transform=, exclude=) decorator registering on a
  module-level default_mapper (exported as pyfly.data.mapping / default_mapper).

Existing Mapper API unchanged/back-compatible. Tests: tests/data/test_mapper_nested.py (4),
existing test_mapper{,_projection}.py (16) green. Gates: mypy --strict (609), ruff + format,
full suite 3746 passed.
@ancongui ancongui merged commit 2f5415a into main Jun 7, 2026
5 checks passed
@ancongui ancongui deleted the feat/mapper-pydantic-nested branch June 7, 2026 08:20
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