Pass relevant `JsonWriterOptions` from the `KiotaJsonSerializationContext.Options` to the `Utf8JsonWriter` when writing json to enable customization. #281
Trying out the code below, the Encode settings seem to have no effect on the serialized payload.
var jsonSerializationOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
var kiotaJsonSerializationContext = new KiotaJsonSerializationContext(jsonSerializationOptions); // create serialization context with custom options
SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories["application/json"] = new JsonSerializationWriterFactory(kiotaJsonSerializationContext); // replace the json serializer with one with custom options
var requestJson = await KiotaJsonSerializer.SerializeAsStringAsync(request);
This is because, the JsonSerializationWriter initializes a Utf8JsonWriter instance without propagating relelvant options to the JsonWriterOptions parameter in the constructor here.
Related to discussion at https://github.com/microsoft/kiota/discussions/4898#discussioncomment-9949732
Trying out the code below, the Encode settings seem to have no effect on the serialized payload.
This is because, the
JsonSerializationWriter
initializes aUtf8JsonWriter
instance without propagating relelvant options to theJsonWriterOptions
parameter in the constructor here.https://github.com/microsoft/kiota-serialization-json-dotnet/blob/046356f4e43767b12cfa7b6d223671d83e63309c/src/JsonSerializationWriter.cs#L51
The line should probably be updated to something as below and relevant tests added.