@@ -141,6 +141,56 @@ public void CanDeserializeDictionaryKeys_WithSystemTextJsonProvider()
141141 Assert . True ( deserialized . Values . ContainsKey ( guid ) ) ;
142142 Assert . Equal ( "My Value" , deserialized . Values [ guid ] ) ;
143143 }
144+
145+ [ Fact ]
146+ public void CanSerializeToGuid_WithSystemTextJsonProvider_WithSourceGenerator ( )
147+ {
148+ var foo = GuidId1 . New ( ) ;
149+
150+ var serializedFoo = SystemTextJsonSerializer . Serialize ( foo , SystemTextJsonSerializerContext . Custom . GuidId1 ) ;
151+ var serializedGuid = SystemTextJsonSerializer . Serialize ( foo . Value ) ;
152+
153+ Assert . Equal ( serializedFoo , serializedGuid ) ;
154+ }
155+
156+ [ Fact ]
157+ public void CanDeserializeFromGuid_WithSystemTextJsonProvider_WithSourceGenerator ( )
158+ {
159+ var value = Guid . NewGuid ( ) ;
160+ var foo = new GuidId1 ( value ) ;
161+ var serializedGuid = SystemTextJsonSerializer . Serialize ( value ) ;
162+
163+ var deserializedFoo = SystemTextJsonSerializer . Deserialize < GuidId1 > ( serializedGuid , SystemTextJsonSerializerContext . Custom . GuidId1 ) ;
164+
165+ Assert . Equal ( foo , deserializedFoo ) ;
166+ }
167+
168+ [ Fact ( Skip = "This one doesn't seem to work, but I'm not sure if it's a source-generator limitation or a bug..." ) ]
169+ public void CanDeserializeDictionaryKeys_WithSystemTextJsonProvider_WithSourceGenerator ( )
170+ {
171+ var value = new TypeWithDictionaryKeys ( )
172+ {
173+ Values = new ( )
174+ } ;
175+ var guid = new GuidId1 ( Guid . Parse ( "78104553-f1cd-41ec-bcb6-d3a8ff8d994d" ) ) ;
176+ value . Values . Add ( guid , "My Value" ) ;
177+ var serialized = SystemTextJsonSerializer . Serialize ( value , SystemTextJsonSerializerContext . Web . TypeWithDictionaryKeys ) ;
178+
179+ var expected = $$ """
180+ {
181+ "values": {
182+ "78104553-f1cd-41ec-bcb6-d3a8ff8d994d": "My Value"
183+ }
184+ }
185+ """ ;
186+ Assert . Equal ( serialized , expected ) ;
187+
188+ var deserialized = SystemTextJsonSerializer . Deserialize < TypeWithDictionaryKeys > ( serialized , SystemTextJsonSerializerContext . Web . TypeWithDictionaryKeys ) ;
189+
190+ Assert . NotNull ( deserialized . Values ) ;
191+ Assert . True ( deserialized . Values . ContainsKey ( guid ) ) ;
192+ Assert . Equal ( "My Value" , deserialized . Values [ guid ] ) ;
193+ }
144194#endif
145195
146196 [ Fact ]
0 commit comments