Skip to content

Commit

Permalink
different null validation messages for complex and primitive collections
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio committed Jun 3, 2020
1 parent 33e8a0b commit db2720e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ protected ODataJsonLightReaderNestedResourceInfo InnerReadUndeclaredProperty(IOD

// Complex property or collection of complex property.
bool isCollection = payloadTypeReference.IsCollection();
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName);
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName, payloadTypeReference);
if (isCollection)
{
readerNestedResourceInfo = this.ReadingResponse
Expand Down Expand Up @@ -473,7 +473,8 @@ protected ODataJsonLightReaderNestedResourceInfo InnerReadUndeclaredProperty(IOD
/// <param name="jsonReader">The IJsonReader.</param>
/// <param name="isCollection">true if the property is entity set reference property; false for a resource reference property, null if unknown.</param>
/// <param name="propertyName">Name for the navigation property, used in error message only.</param>
protected static void ValidateExpandedNestedResourceInfoPropertyValue(IJsonReader jsonReader, bool? isCollection, string propertyName)
/// <param name="typeReference">Type of navigation property</param>
protected static void ValidateExpandedNestedResourceInfoPropertyValue(IJsonReader jsonReader, bool? isCollection, string propertyName, IEdmTypeReference typeReference)
{
// an expanded link with resource requires a StartObject node here;
// an expanded link with resource set requires a StartArray node here;
Expand All @@ -491,7 +492,22 @@ protected static void ValidateExpandedNestedResourceInfoPropertyValue(IJsonReade
// Expanded resource (null or non-null)
if (isCollection == true)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightResourceDeserializer_CannotReadCollectionNestedResource(nodeType, propertyName));
//
if (typeReference.IsODataPrimitiveTypeKind() ||
typeReference.IsODataTypeDefinitionTypeKind() ||
typeReference.IsODataEnumTypeKind() ||
typeReference.IsODataComplexTypeKind() ||
typeReference.IsUntyped() ||
typeReference.IsNonEntityCollectionType())
{
ReaderValidationUtils.ValidateNullValue(typeReference, true,
true, propertyName, false);
}
else
{
throw new ODataException(ODataErrorStrings.ODataJsonLightResourceDeserializer_CannotReadCollectionNestedResource(nodeType, propertyName));
}

}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ private ODataJsonLightReaderNestedInfo ReadPropertyWithValue(IODataJsonLightRead
ODataJsonLightReaderNestedResourceInfo readerNestedResourceInfo = null;

// Complex property or collection of complex property.
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName);
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName, edmProperty.Type);

if (isCollection)
{
Expand All @@ -1251,7 +1251,7 @@ private ODataJsonLightReaderNestedInfo ReadPropertyWithValue(IODataJsonLightRead
ODataJsonLightReaderNestedResourceInfo readerNestedResourceInfo = null;

// Expanded link
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName);
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName, edmProperty.Type);
if (isCollection)
{
readerNestedResourceInfo = this.ReadingResponse || isDeltaResourceSet
Expand Down Expand Up @@ -1548,7 +1548,7 @@ private ODataJsonLightReaderNestedInfo InnerReadUndeclaredProperty(IODataJsonLig
if (payloadTypeOrItemType != null)
{
// Complex property or collection of complex property.
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName);
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName, payloadTypeReference);
if (isCollection)
{
return ReadNonExpandedResourceSetNestedResourceInfo(resourceState, null, payloadTypeOrItemType, propertyName);
Expand Down Expand Up @@ -1668,7 +1668,7 @@ private ODataJsonLightReaderNestedInfo ReadUndeclaredProperty(IODataJsonLightRea
// If the property is expanded, ignore the content if we're asked to do so.
if (propertyWithValue)
{
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, null, propertyName);
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, null, propertyName, resourceState.ResourceType.ToTypeReference());

// Since we marked the nested resource info as deferred the reader will not try to read its content
// instead it will behave as if it was a real deferred link (without a property value).
Expand Down

0 comments on commit db2720e

Please sign in to comment.