Skip to content

Commit

Permalink
Fix to mitigate possible bug in JsonLightInstanceAnnotationWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
John Gathogo committed Apr 8, 2021
1 parent 40c33e5 commit b16b4d7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/Microsoft.OData.Core/Json/JsonLightInstanceAnnotationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ internal sealed class JsonLightInstanceAnnotationWriter
/// </summary>
private readonly JsonLightODataAnnotationWriter odataAnnotationWriter;

/// <summary>
/// Asynchronous OData annotation writer.
/// </summary>
private readonly JsonLightODataAnnotationWriter asynchronousODataAnnotationWriter;

/// <summary>
/// The writer validator used during writing.
/// </summary>
Expand All @@ -64,18 +69,10 @@ internal JsonLightInstanceAnnotationWriter(ODataJsonLightValueSerializer valueSe
Debug.Assert(valueSerializer != null, "valueSerializer should not be null");
this.valueSerializer = valueSerializer;
this.typeNameOracle = typeNameOracle;
if (this.valueSerializer.JsonLightOutputContext.Synchronous)
{
this.jsonWriter = this.valueSerializer.JsonWriter;
this.odataAnnotationWriter = new JsonLightODataAnnotationWriter(this.jsonWriter,
valueSerializer.JsonLightOutputContext.OmitODataPrefix, this.valueSerializer.MessageWriterSettings.Version);
}
else
{
this.asynchronousJsonWriter = this.valueSerializer.AsynchronousJsonWriter;
this.odataAnnotationWriter = new JsonLightODataAnnotationWriter(this.asynchronousJsonWriter,
valueSerializer.JsonLightOutputContext.OmitODataPrefix, this.valueSerializer.MessageWriterSettings.Version);
}
this.jsonWriter = this.valueSerializer.JsonWriter;
this.odataAnnotationWriter = this.valueSerializer.ODataAnnotationWriter;
this.asynchronousJsonWriter = this.valueSerializer.AsynchronousJsonWriter;
this.asynchronousODataAnnotationWriter = this.valueSerializer.AsynchronousODataAnnotationWriter;
this.writerValidator = this.valueSerializer.MessageWriterSettings.Validator;
}

Expand Down Expand Up @@ -372,7 +369,7 @@ await this.valueSerializer.WriteResourceValueAsync(resourceValue,
string collectionTypeNameToWrite = this.typeNameOracle.GetValueTypeNameForWriting(collectionValue, expectedType, typeFromCollectionValue, treatLikeOpenProperty);
if (collectionTypeNameToWrite != null)
{
await this.odataAnnotationWriter.WriteODataTypePropertyAnnotationAsync(annotationName, collectionTypeNameToWrite)
await this.asynchronousODataAnnotationWriter.WriteODataTypePropertyAnnotationAsync(annotationName, collectionTypeNameToWrite)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -416,7 +413,7 @@ await this.valueSerializer.WriteEnumValueAsync(enumValue, expectedType)
string primitiveTypeNameToWrite = this.typeNameOracle.GetValueTypeNameForWriting(primitiveValue, expectedType, typeFromPrimitiveValue, treatLikeOpenProperty);
if (primitiveTypeNameToWrite != null)
{
await this.odataAnnotationWriter.WriteODataTypePropertyAnnotationAsync(annotationName, primitiveTypeNameToWrite)
await this.asynchronousODataAnnotationWriter.WriteODataTypePropertyAnnotationAsync(annotationName, primitiveTypeNameToWrite)
.ConfigureAwait(false);
}

Expand Down

0 comments on commit b16b4d7

Please sign in to comment.