@@ -1049,27 +1049,71 @@ public static void ImmutableDictionaryPreserveNestedObjects()
10491049 }
10501050
10511051 [ Theory ]
1052- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/1902" ) ]
1053- [ InlineData ( @"{""$id"": {}}" , "$.$id" ) ]
1054- [ InlineData ( @"{""$id"": }" , "$.$id" ) ]
1055- [ InlineData ( @"{""$id"": []}" , "$.$id" ) ]
1056- [ InlineData ( @"{""$id"": ]" , "$.$id" ) ]
1057- [ InlineData ( @"{""$id"": null}" , "$.$id" ) ]
1058- [ InlineData ( @"{""$id"": true}" , "$.$id" ) ]
1059- [ InlineData ( @"{""$id"": false}" , "$.$id" ) ]
1060- [ InlineData ( @"{""$id"": 10}" , "$.$id" ) ]
1061- [ InlineData ( @"{""$ref"": {}}" , "$.$ref" ) ]
1062- [ InlineData ( @"{""$ref"": }" , "$.$ref" ) ]
1063- [ InlineData ( @"{""$ref"": []}" , "$.$ref" ) ]
1064- [ InlineData ( @"{""$ref"": ]" , "$.$ref" ) ]
1065- [ InlineData ( @"{""$ref"": null}" , "$.$ref" ) ]
1066- [ InlineData ( @"{""$ref"": true}" , "$.$ref" ) ]
1067- [ InlineData ( @"{""$ref"": false}" , "$.$ref" ) ]
1068- [ InlineData ( @"{""$ref"": 10}" , "$.$ref" ) ]
1069- public static void IdAndRefContainInvalidToken ( string json , string expectedPath )
1052+ [ InlineData ( @"{""$id"":{}}" , JsonTokenType . StartObject ) ]
1053+ [ InlineData ( @"{""$id"":[]}" , JsonTokenType . StartArray ) ]
1054+ [ InlineData ( @"{""$id"":null}" , JsonTokenType . Null ) ]
1055+ [ InlineData ( @"{""$id"":true}" , JsonTokenType . True ) ]
1056+ [ InlineData ( @"{""$id"":false}" , JsonTokenType . False ) ]
1057+ [ InlineData ( @"{""$id"":9}" , JsonTokenType . Number ) ]
1058+ // Invalid JSON, the reader will throw before we reach the serializer validation.
1059+ [ InlineData ( @"{""$id"":}" , JsonTokenType . None ) ]
1060+ [ InlineData ( @"{""$id"":]" , JsonTokenType . None ) ]
1061+ public static void MetadataId_StartsWithInvalidToken ( string json , JsonTokenType incorrectToken )
10701062 {
1071- JsonException ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < EmployeeWithImmutable > ( json , s_deserializerOptionsPreserve ) ) ;
1072- Assert . Equal ( expectedPath , ex . Path ) ;
1063+ JsonException ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < Employee > ( json , s_deserializerOptionsPreserve ) ) ;
1064+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1065+ Assert . Equal ( "$.$id" , ex . Path ) ;
1066+
1067+ ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < Dictionary < string , string > > ( json , s_deserializerOptionsPreserve ) ) ;
1068+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1069+ Assert . Equal ( "$.$id" , ex . Path ) ;
1070+
1071+ ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < List < int > > ( json , s_deserializerOptionsPreserve ) ) ;
1072+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1073+ Assert . Equal ( "$.$id" , ex . Path ) ;
1074+ }
1075+
1076+
1077+ [ Theory ]
1078+ [ InlineData ( @"{""$ref"":{}}" , JsonTokenType . StartObject ) ]
1079+ [ InlineData ( @"{""$ref"":[]}" , JsonTokenType . StartArray ) ]
1080+ [ InlineData ( @"{""$ref"":null}" , JsonTokenType . Null ) ]
1081+ [ InlineData ( @"{""$ref"":true}" , JsonTokenType . True ) ]
1082+ [ InlineData ( @"{""$ref"":false}" , JsonTokenType . False ) ]
1083+ [ InlineData ( @"{""$ref"":9}" , JsonTokenType . Number ) ]
1084+ // Invalid JSON, the reader will throw before we reach the serializer validation.
1085+ [ InlineData ( @"{""$ref"":}" , JsonTokenType . None ) ]
1086+ [ InlineData ( @"{""$ref"":]" , JsonTokenType . None ) ]
1087+ public static void MetadataRef_StartsWithInvalidToken ( string json , JsonTokenType incorrectToken )
1088+ {
1089+ JsonException ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < Employee > ( json , s_deserializerOptionsPreserve ) ) ;
1090+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1091+ Assert . Equal ( "$.$ref" , ex . Path ) ;
1092+
1093+ ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < Dictionary < string , string > > ( json , s_deserializerOptionsPreserve ) ) ;
1094+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1095+ Assert . Equal ( "$.$ref" , ex . Path ) ;
1096+
1097+ ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < List < int > > ( json , s_deserializerOptionsPreserve ) ) ;
1098+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1099+ Assert . Equal ( "$.$ref" , ex . Path ) ;
1100+ }
1101+
1102+ [ Theory ]
1103+ [ InlineData ( @"{""$id"":""1"",""$values"":{}}" , JsonTokenType . StartObject ) ]
1104+ [ InlineData ( @"{""$id"":""1"",""$values"":null}" , JsonTokenType . Null ) ]
1105+ [ InlineData ( @"{""$id"":""1"",""$values"":true}" , JsonTokenType . True ) ]
1106+ [ InlineData ( @"{""$id"":""1"",""$values"":false}" , JsonTokenType . False ) ]
1107+ [ InlineData ( @"{""$id"":""1"",""$values"":9}" , JsonTokenType . Number ) ]
1108+ [ InlineData ( @"{""$id"":""1"",""$values"":""9""}" , JsonTokenType . String ) ]
1109+ // Invalid JSON, the reader will throw before we reach the serializer validation.
1110+ [ InlineData ( @"{""$id"":""1"",""$values"":}" , JsonTokenType . None ) ]
1111+ [ InlineData ( @"{""$id"":""1"",""$values"":]" , JsonTokenType . None ) ]
1112+ public static void MetadataValues_StartsWithInvalidToken ( string json , JsonTokenType incorrectToken )
1113+ {
1114+ JsonException ex = Assert . Throws < JsonException > ( ( ) => JsonSerializer . Deserialize < List < int > > ( json , s_deserializerOptionsPreserve ) ) ;
1115+ Assert . True ( incorrectToken == JsonTokenType . None || ex . Message . Contains ( $ "'{ incorrectToken } '") ) ;
1116+ Assert . Equal ( "$.$values" , ex . Path ) ;
10731117 }
10741118 #endregion
10751119
0 commit comments