@@ -143,6 +143,58 @@ public void CanDeserializeDictionaryKeys_WithSystemTextJsonProvider()
143143 }
144144#endif
145145
146+ [ Fact ]
147+ public void CanSerializeToGuid_WithSystemTextJsonProvider_WithSourceGenerator ( )
148+ {
149+ var foo = GuidId1 . New ( ) ;
150+
151+ var serializedFoo = SystemTextJsonSerializer . Serialize ( foo , SystemTextJsonSerializerContext . Custom . GuidId1 ) ;
152+ var serializedGuid = SystemTextJsonSerializer . Serialize ( foo . Value ) ;
153+
154+ Assert . Equal ( serializedFoo , serializedGuid ) ;
155+ }
156+
157+ [ Fact ]
158+ public void CanDeserializeFromGuid_WithSystemTextJsonProvider_WithSourceGenerator ( )
159+ {
160+ var value = Guid . NewGuid ( ) ;
161+ var foo = new GuidId1 ( value ) ;
162+ var serializedGuid = SystemTextJsonSerializer . Serialize ( value , SystemTextJsonSerializerContext . Custom . GuidId1 ) ;
163+
164+ var deserializedFoo = SystemTextJsonSerializer . Deserialize < GuidId1 > ( serializedGuid , SystemTextJsonSerializerContext . Custom . GuidId1 ) ;
165+
166+ Assert . Equal ( foo , deserializedFoo ) ;
167+ }
168+
169+ #if NET6_0_OR_GREATER
170+ [ Fact ]
171+ public void CanDeserializeDictionaryKeys_WithSystemTextJsonProvider_WithSourceGenerator ( )
172+ {
173+ var value = new TypeWithDictionaryKeys ( )
174+ {
175+ Values = new ( )
176+ } ;
177+ var guid = new GuidId1 ( Guid . Parse ( "78104553-f1cd-41ec-bcb6-d3a8ff8d994d" ) ) ;
178+ value . Values . Add ( guid , "My Value" ) ;
179+ var serialized = SystemTextJsonSerializer . Serialize ( value , SystemTextJsonSerializerContext . Web . TypeWithDictionaryKeys ) ;
180+
181+ var expected = $$ """
182+ {
183+ "values": {
184+ "78104553-f1cd-41ec-bcb6-d3a8ff8d994d": "My Value"
185+ }
186+ }
187+ """ ;
188+ Assert . Equal ( serialized , expected ) ;
189+
190+ var deserialized = SystemTextJsonSerializer . Deserialize < TypeWithDictionaryKeys > ( serialized , SystemTextJsonSerializerContext . Web . TypeWithDictionaryKeys ) ;
191+
192+ Assert . NotNull ( deserialized . Values ) ;
193+ Assert . True ( deserialized . Values . ContainsKey ( guid ) ) ;
194+ Assert . Equal ( "My Value" , deserialized . Values [ guid ] ) ;
195+ }
196+ #endif
197+
146198 [ Fact ]
147199 public void WhenNoJsonConverter_NewtonsoftSerializesWithoutValueProperty ( )
148200 {
0 commit comments