Skip to content

Commit

Permalink
JsonSerializerOptions gets defaulted
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Oct 19, 2024
1 parent 7eec571 commit 00f7ecf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Shiny.Mediator/Infrastructure/SerializerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ public interface ISerializerService

public class SerializerService : ISerializerService
{
readonly JsonSerializerOptions jsonOptions;

public SerializerService(JsonSerializerOptions? options = null)
public SerializerService()
{
this.jsonOptions = options ?? new JsonSerializerOptions
this.JsonOptions = new JsonSerializerOptions
{
Converters =
{
Expand All @@ -24,15 +22,18 @@ public SerializerService(JsonSerializerOptions? options = null)
};
}


public JsonSerializerOptions JsonOptions { get; set; }

public string Serialize<T>(T obj)
{
var json = JsonSerializer.Serialize(obj, this.jsonOptions);
var json = JsonSerializer.Serialize(obj, this.JsonOptions);
return json;
}

public T Deserialize<T>(string json)
{
var obj = JsonSerializer.Deserialize<T>(json, this.jsonOptions)!;
var obj = JsonSerializer.Deserialize<T>(json, this.JsonOptions)!;
return obj;
}
}

0 comments on commit 00f7ecf

Please sign in to comment.