File tree Expand file tree Collapse file tree 2 files changed +6
-22
lines changed
samples/Foundatio.HostingSample Expand file tree Collapse file tree 2 files changed +6
-22
lines changed Original file line number Diff line number Diff line change 3535 . AddCaching ( ) . UseInMemory ( )
3636 . AddLocking ( ) . UseCache ( )
3737 . AddMessaging ( ) . UseInMemory ( )
38- . AddQueueing ( ) . UseInMemory < SampleWork > ( )
39- . AddSerializer ( sp => new SystemTextJsonSerializer ( sp . GetRequiredService < IOptions < JsonOptions > > ( ) . Value . SerializerOptions , sp . GetRequiredService < IOptions < JsonOptions > > ( ) . Value . SerializerOptions ) )
38+ . AddSerializer ( sp => new SystemTextJsonSerializer ( sp . GetRequiredService < IOptions < JsonOptions > > ( ) . Value . SerializerOptions ) )
4039 . AddResilience ( b => b . WithPolicy < Sample1Job > ( p => p . WithMaxAttempts ( 5 ) . WithLinearDelay ( ) . WithJitter ( ) ) ) ;
4140
4241ConfigureServices ( ) ;
@@ -219,5 +218,3 @@ void ConfigureServices()
219218 . AddMessaging ( ) . UseRedis ( ) ;
220219#endif
221220}
222-
223- public class SampleWork { }
Original file line number Diff line number Diff line change @@ -7,29 +7,16 @@ namespace Foundatio.Serializer;
77
88public class SystemTextJsonSerializer : ITextSerializer
99{
10+ private readonly JsonSerializerOptions _defaultSerializeOptions = new ( ) ;
11+ private readonly JsonSerializerOptions _defaultDeserializeOptions = new ( ) { Converters = { new ObjectToInferredTypesConverter ( ) } } ;
12+
1013 private readonly JsonSerializerOptions _serializeOptions ;
1114 private readonly JsonSerializerOptions _deserializeOptions ;
1215
1316 public SystemTextJsonSerializer ( JsonSerializerOptions serializeOptions = null , JsonSerializerOptions deserializeOptions = null )
1417 {
15- if ( serializeOptions != null )
16- {
17- _serializeOptions = serializeOptions ;
18- }
19- else
20- {
21- _serializeOptions = new JsonSerializerOptions ( ) ;
22- }
23-
24- if ( deserializeOptions != null )
25- {
26- _deserializeOptions = deserializeOptions ;
27- }
28- else
29- {
30- _deserializeOptions = new JsonSerializerOptions ( ) ;
31- _deserializeOptions . Converters . Add ( new ObjectToInferredTypesConverter ( ) ) ;
32- }
18+ _serializeOptions = serializeOptions ?? _defaultSerializeOptions ;
19+ _deserializeOptions = deserializeOptions ?? serializeOptions ?? _defaultDeserializeOptions ;
3320 }
3421
3522 public void Serialize ( object data , Stream outputStream )
You can’t perform that action at this time.
0 commit comments