Skip to content

Commit f88de90

Browse files
committed
Update readme
1 parent 5b07c74 commit f88de90

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Make sure you have the appropriate .NET target framework installed. This package
2323

2424
## Usage
2525

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`
2729

2830
```csharp
2931
public class MyModel
@@ -34,11 +36,7 @@ public class MyModel
3436
[JsonDateTimeConverter("yyyy-MM-ddTHH:mm:ss.fffZ")]
3537
public DateTimeOffset DateTimeOffset { get; set; }
3638
}
37-
```
38-
39-
### Example Program
4039

41-
```csharp
4240
public class Program
4341
{
4442
public static void Main()
@@ -61,9 +59,11 @@ public class Program
6159
}
6260
```
6361

64-
### Source Generator Example
62+
**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`
6565

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`.
6767

6868
#### Example Model
6969

@@ -118,6 +118,9 @@ public class Program
118118
}
119119
```
120120

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+
121124
## Notes
122125

123126
- The `JsonDateTimeConverterAttribute` and `JsonDateTimeFormatConverter` can be applied to properties of type `DateTime`, `DateTime?`, `DateTimeOffset`, and `DateTimeOffset?`.

0 commit comments

Comments
 (0)