Skip to content

Commit

Permalink
Allowing trailing commas in config json file
Browse files Browse the repository at this point in the history
  • Loading branch information
TalZaccai committed Oct 31, 2024
1 parent 9ebabe8 commit 08cd571
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libs/host/Configuration/ConfigProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ public bool TryImportOptions(string path, IStreamProvider streamProvider, Option
var jsonSerializerOptions = new JsonSerializerOptions
{
Converters = { new PopulateObjectJsonConverter<Options>(options), new JsonStringEnumConverter() },
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString,
};

var json = streamReader.ReadToEnd();
var jsonReaderOptions = new JsonReaderOptions { CommentHandling = JsonCommentHandling.Skip };

var jsonReaderOptions = new JsonReaderOptions
{
CommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true
};

var jsonReader = new Utf8JsonReader(new ReadOnlySpan<byte>(Encoding.UTF8.GetBytes(json)), jsonReaderOptions);

// No need fot the return value, as the deserializer populates the existing options instance
Expand Down
3 changes: 2 additions & 1 deletion test/Garnet.test/GarnetServerConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void DefaultConfigurationOptionsCoverage()
var jsonSerializerOptions = new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Skip,
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString,
AllowTrailingCommas = true,
};

try
Expand Down

0 comments on commit 08cd571

Please sign in to comment.