File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -441,18 +441,28 @@ Generated row classes can be converted from and to JSON:
441441
442442### Key names
443443
444- By default, drift uses column names in ` snake_case ` as JSON keys:
444+ For tables and views defined as Dart classes, drift uses the name of the getter defining columns as
445+ a JSON key:
445446
446447{{ load_snippet('default-json-keys','lib/snippets/dart_api/dataclass.dart.excerpt.json') }}
447448
448449``` json
449450{
450451 "id" : 1 ,
451452 "title" : " Todo 1" ,
452- "created_at " : " 2024-02-29T12:00:00Z"
453+ "createdAt " : " 2024-02-29T12:00:00Z"
453454}
454455```
455456
457+ For elements defined in [ drift files] ( ../sql_api/drift_files.md ) , drift uses the name of the column
458+ in SQL instead. This can be a problem when mixing the two declarations. A view defined in a drift file
459+ that selects from the Dart table would have different JSON keys, for instance:
460+
461+ ``` sql
462+ -- JSON keys are id, title, created_at
463+ CREATE VIEW todos_view AS SELECT * FROM todos;
464+ ```
465+
456466#### Custom json keys
457467
458468To use a custom name for JSON serialization, use the ` @JsonKey ` annotation.
You can’t perform that action at this time.
0 commit comments