|
1 | 1 | # Field Configuration |
2 | 2 |
|
3 | | -Documentation coming soon. See [Phase 1 Requirements](../roadmap/phase-1.md) for detailed specifications. |
| 3 | +Field configuration is handled through `[DynamoField]` attributes on the mapper class. These |
| 4 | +attributes target model properties and allow you to override defaults without touching your domain |
| 5 | +models. |
| 6 | + |
| 7 | +## Basic Usage |
| 8 | + |
| 9 | +```csharp |
| 10 | +using DynamoMapper.Runtime; |
| 11 | + |
| 12 | +[DynamoMapper] |
| 13 | +[DynamoField(nameof(Product.Name), AttributeName = "productName", Required = true)] |
| 14 | +[DynamoField(nameof(Product.Description), OmitIfNull = true, OmitIfEmptyString = true)] |
| 15 | +public static partial class ProductMapper |
| 16 | +{ |
| 17 | + public static partial Dictionary<string, AttributeValue> ToItem(Product source); |
| 18 | + public static partial Product FromItem(Dictionary<string, AttributeValue> item); |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +## Nested Property Overrides (Dot Notation) |
| 23 | + |
| 24 | +Use dot notation to override nested properties without adding attributes to nested types: |
| 25 | + |
| 26 | +```csharp |
| 27 | +[DynamoMapper] |
| 28 | +[DynamoField("ShippingAddress.Line1", AttributeName = "addr_line1")] |
| 29 | +[DynamoField("ShippingAddress.City", AttributeName = "addr_city")] |
| 30 | +public static partial class OrderMapper |
| 31 | +{ |
| 32 | + public static partial Dictionary<string, AttributeValue> ToItem(Order source); |
| 33 | + public static partial Order FromItem(Dictionary<string, AttributeValue> item); |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +Notes: |
| 38 | +- Dot-notation overrides force inline mapping for the nested path. |
| 39 | +- Invalid paths emit `DM0008`. |
| 40 | + |
| 41 | +## Supported Options |
| 42 | + |
| 43 | +| Option | Description | |
| 44 | +| --- | --- | |
| 45 | +| `AttributeName` | Overrides the DynamoDB attribute name. | |
| 46 | +| `Required` | Controls requiredness during `FromItem`. | |
| 47 | +| `Kind` | Forces a specific `DynamoKind`. | |
| 48 | +| `OmitIfNull` | Omits null values during `ToItem`. | |
| 49 | +| `OmitIfEmptyString` | Omits empty strings during `ToItem`. | |
| 50 | +| `ToMethod` | Uses a custom method to serialize a value. | |
| 51 | +| `FromMethod` | Uses a custom method to deserialize a value. | |
| 52 | +| `Format` | Overrides default format for date/time/enum conversions. | |
0 commit comments