Example: Using field aliases.
()
| 150 | |
| 151 | |
| 152 | def example_field_aliases(): |
| 153 | """Example: Using field aliases.""" |
| 154 | print("=== Field Aliases ===") |
| 155 | |
| 156 | order = Order( |
| 157 | orderId='ORD-12345', |
| 158 | customerName='Diana Prince', |
| 159 | products=[ |
| 160 | Product(sku='LAP-001', name='Gaming Laptop', price=1299.99, stock=15), |
| 161 | Product(sku='MOU-042', name='Wireless Mouse', price=29.99, stock=128) |
| 162 | ], |
| 163 | total=1329.98 |
| 164 | ) |
| 165 | |
| 166 | print("Without aliases (internal field names):") |
| 167 | toon_no_alias = encode_pydantic(order, by_alias=False) |
| 168 | print(toon_no_alias) |
| 169 | print() |
| 170 | |
| 171 | print("With aliases (API field names):") |
| 172 | toon_alias = encode_pydantic(order, by_alias=True) |
| 173 | print(toon_alias) |
| 174 | print() |
| 175 | |
| 176 | |
| 177 | def example_decoding(): |
no test coverage detected
searching dependent graphs…