You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,9 @@ Make sure you have the appropriate .NET target framework installed. This package
23
23
24
24
## Usage
25
25
26
-
### Example Model
26
+
Examples of how to serialize and deserialize models with custom date formats using `JsonDateTimeConverter` and `JsonDateTimeFormatConverter`. Note the differences when using source generators with `System.Text.Json`.
27
+
28
+
### Using reflection based with `JsonDateTimeConverter`
**Note:**`JsonDateTimeConverter` does not support `System.Text.Json` source generators. Using this converter with `JsonSerializerContext` results in **SYSLIB1223**: "Attributes deriving from `JsonConverterAttribute` are not supported by the source generator." For such cases, use `JsonDateTimeFormatConverter`.
63
+
64
+
### Using Source Generators with `JsonDateTimeFormatConverter`
65
65
66
-
If you are using source generators with `System.Text.Json`, you should use `JsonDateTimeFormatConverter` instead of `JsonDateTimeConverterAttribute`.
66
+
To work with `System.Text.Json` source generators, use `JsonDateTimeFormatConverter` instead of `JsonDateTimeConverterAttribute`.
67
67
68
68
#### Example Model
69
69
@@ -118,6 +118,9 @@ public class Program
118
118
}
119
119
```
120
120
121
+
Unfortunately, there is no better way with the source generator than defining a class for each date-time format. This is because the `JsonConverterAttribute` is not supported by the source generator, and neither `JsonConverterFactory` nor `JsonConverter` allows passing the format string to the converter, as they lack constructors with parameters.
122
+
The new contract customization does not provide attribute support for the source generator as well.
123
+
121
124
## Notes
122
125
123
126
- The `JsonDateTimeConverterAttribute` and `JsonDateTimeFormatConverter` can be applied to properties of type `DateTime`, `DateTime?`, `DateTimeOffset`, and `DateTimeOffset?`.
0 commit comments