@@ -53,22 +53,35 @@ public sealed class JsonStateStringParser(
5353 /// <summary>Singleton instance</summary>
5454 public static IStateStringParser Singleton => singleton . Value ;
5555
56- internal Logger ? Logger = null ;
57- readonly JsonSerializerOptions jsonOptions = options ?? CreateDefaultJsonOptions ( ) ;
58- readonly IStateStringParser fallback = stateStringFallback ?? new DefaultStateStringParser ( ) ;
59- readonly HexStateStringParser nullFallback = new ( ) ;
60-
61- internal static JsonSerializerOptions CreateDefaultJsonOptions ( ) =>
62- new ( )
56+ static JsonSerializerOptions CreateDefaultJsonOptions ( Action < JsonSerializerOptions > ? configure = null )
57+ {
58+ JsonSerializerOptions options = new ( )
6359 {
6460 WriteIndented = true ,
6561 IncludeFields = true ,
6662 AllowTrailingCommas = true ,
63+ DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingNull ,
6764 ReferenceHandler = ReferenceHandler . IgnoreCycles ,
6865 Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping ,
6966 Converters = { new JsonStringEnumConverter ( ) } ,
7067 } ;
7168
69+ configure ? . Invoke ( options ) ;
70+ return options ;
71+ }
72+
73+ internal Logger ? Logger = null ;
74+ readonly JsonSerializerOptions jsonOptions = options ?? CreateDefaultJsonOptions ( ) ;
75+ readonly IStateStringParser fallback = stateStringFallback ?? new DefaultStateStringParser ( ) ;
76+ readonly HexStateStringParser nullFallback = new ( ) ;
77+
78+ /// <summary>
79+ /// Create and configure a JSON <see cref="IStateStringParser"/>
80+ /// </summary>
81+ public JsonStateStringParser ( Action < JsonSerializerOptions > configure ,
82+ IStateStringParser ? stateStringFallback = null ) :
83+ this ( CreateDefaultJsonOptions ( configure ) , stateStringFallback ) { }
84+
7285 /// <inheritdoc />
7386 public string GetStateString ( in Frame frame , ref readonly BinaryBufferReader reader , object ? currentState )
7487 {
0 commit comments