@@ -25,9 +25,12 @@ private sealed class Parser
25
25
private const string SystemTextJsonNamespace = "System.Text.Json" ;
26
26
private const string JsonConverterAttributeFullName = "System.Text.Json.Serialization.JsonConverterAttribute" ;
27
27
private const string JsonConverterFactoryFullName = "System.Text.Json.Serialization.JsonConverterFactory" ;
28
+ private const string JsonArrayFullName = "System.Text.Json.Nodes.JsonArray" ;
28
29
private const string JsonElementFullName = "System.Text.Json.JsonElement" ;
29
30
private const string JsonExtensionDataAttributeFullName = "System.Text.Json.Serialization.JsonExtensionDataAttribute" ;
31
+ private const string JsonNodeFullName = "System.Text.Json.Nodes.JsonNode" ;
30
32
private const string JsonObjectFullName = "System.Text.Json.Nodes.JsonObject" ;
33
+ private const string JsonValueFullName = "System.Text.Json.Nodes.JsonValue" ;
31
34
private const string JsonIgnoreAttributeFullName = "System.Text.Json.Serialization.JsonIgnoreAttribute" ;
32
35
private const string JsonIgnoreConditionFullName = "System.Text.Json.Serialization.JsonIgnoreCondition" ;
33
36
private const string JsonIncludeAttributeFullName = "System.Text.Json.Serialization.JsonIncludeAttribute" ;
@@ -80,8 +83,11 @@ private sealed class Parser
80
83
private readonly Type ? _guidType ;
81
84
private readonly Type ? _uriType ;
82
85
private readonly Type ? _versionType ;
86
+ private readonly Type ? _jsonArrayType ;
83
87
private readonly Type ? _jsonElementType ;
88
+ private readonly Type ? _jsonNodeType ;
84
89
private readonly Type ? _jsonObjectType ;
90
+ private readonly Type ? _jsonValueType ;
85
91
86
92
// Unsupported types
87
93
private readonly Type _typeType ;
@@ -193,8 +199,11 @@ public Parser(Compilation compilation, in JsonSourceGenerationContext sourceGene
193
199
_guidType = _metadataLoadContext . Resolve ( typeof ( Guid ) ) ;
194
200
_uriType = _metadataLoadContext . Resolve ( typeof ( Uri ) ) ;
195
201
_versionType = _metadataLoadContext . Resolve ( typeof ( Version ) ) ;
202
+ _jsonArrayType = _metadataLoadContext . Resolve ( JsonArrayFullName ) ;
196
203
_jsonElementType = _metadataLoadContext . Resolve ( JsonElementFullName ) ;
204
+ _jsonNodeType = _metadataLoadContext . Resolve ( JsonNodeFullName ) ;
197
205
_jsonObjectType = _metadataLoadContext . Resolve ( JsonObjectFullName ) ;
206
+ _jsonValueType = _metadataLoadContext . Resolve ( JsonValueFullName ) ;
198
207
199
208
// Unsupported types.
200
209
_typeType = _metadataLoadContext . Resolve ( typeof ( Type ) ) ;
@@ -565,14 +574,6 @@ private static bool TryGetClassDeclarationList(INamedTypeSymbol typeSymbol, [Not
565
574
}
566
575
}
567
576
break ;
568
- case nameof ( JsonSourceGenerationOptionsAttribute . IgnoreRuntimeCustomConverters ) :
569
- {
570
- if ( bool . TryParse ( propertyValueStr , out bool value ) )
571
- {
572
- options . IgnoreRuntimeCustomConverters = value ;
573
- }
574
- }
575
- break ;
576
577
case nameof ( JsonSourceGenerationOptionsAttribute . IncludeFields ) :
577
578
{
578
579
if ( bool . TryParse ( propertyValueStr , out bool value ) )
@@ -640,7 +641,7 @@ private TypeGenerationSpec GetOrAddTypeGenerationSpec(Type type, JsonSourceGener
640
641
string ? converterInstatiationLogic = null ;
641
642
bool implementsIJsonOnSerialized = false ;
642
643
bool implementsIJsonOnSerializing = false ;
643
- bool hasEncounteredInitOnlyProperties = false ;
644
+ bool hasInitOnlyProperties = false ;
644
645
bool hasTypeFactoryConverter = false ;
645
646
bool hasPropertyFactoryConverters = false ;
646
647
@@ -972,10 +973,10 @@ void CacheMemberHelper()
972
973
_implicitlyRegisteredTypes . Add ( dataExtensionPropGenSpec ) ;
973
974
}
974
975
975
- if ( ! hasEncounteredInitOnlyProperties && spec . CanUseSetter && spec . IsInitOnlySetter )
976
+ if ( ! hasInitOnlyProperties && spec . CanUseSetter && spec . IsInitOnlySetter )
976
977
{
977
978
_sourceGenerationContext . ReportDiagnostic ( Diagnostic . Create ( InitOnlyPropertyDeserializationNotSupported , Location . None , new string [ ] { type . Name } ) ) ;
978
- hasEncounteredInitOnlyProperties = true ;
979
+ hasInitOnlyProperties = true ;
979
980
}
980
981
981
982
if ( spec . HasJsonInclude && ( ! spec . CanUseGetter || ! spec . CanUseSetter || ! spec . IsPublic ) )
@@ -1454,8 +1455,11 @@ private void PopulateKnownTypes()
1454
1455
AddTypeIfNotNull ( _knownTypes , _guidType ) ;
1455
1456
AddTypeIfNotNull ( _knownTypes , _uriType ) ;
1456
1457
AddTypeIfNotNull ( _knownTypes , _versionType ) ;
1458
+ AddTypeIfNotNull ( _knownTypes , _jsonArrayType ) ;
1457
1459
AddTypeIfNotNull ( _knownTypes , _jsonElementType ) ;
1460
+ AddTypeIfNotNull ( _knownTypes , _jsonNodeType ) ;
1458
1461
AddTypeIfNotNull ( _knownTypes , _jsonObjectType ) ;
1462
+ AddTypeIfNotNull ( _knownTypes , _jsonValueType ) ;
1459
1463
1460
1464
_knownUnsupportedTypes . Add ( _typeType ) ;
1461
1465
_knownUnsupportedTypes . Add ( _serializationInfoType ) ;
0 commit comments