diff --git a/ConsumePlugin/GeneratedSerde.fs b/ConsumePlugin/GeneratedSerde.fs index 32f09e5..56b6431 100644 --- a/ConsumePlugin/GeneratedSerde.fs +++ b/ConsumePlugin/GeneratedSerde.fs @@ -21,7 +21,7 @@ module InnerTypeWithBothJsonSerializeExtension = let node = System.Text.Json.Nodes.JsonObject () do - node.Add (("it's-a-me"), System.Text.Json.Nodes.JsonValue.Create input.Thing) + node.Add (("it's-a-me"), System.Text.Json.Nodes.JsonValue.Create input.Thing) node.Add ( "map", @@ -245,6 +245,7 @@ module InnerTypeWithBothJsonParseExtension = | v -> v) .AsValue() .GetValue () + |> System.Guid.Parse { Thing = Thing diff --git a/ConsumePlugin/SerializationAndDeserialization.fs b/ConsumePlugin/SerializationAndDeserialization.fs index a6fe562..11f34b6 100644 --- a/ConsumePlugin/SerializationAndDeserialization.fs +++ b/ConsumePlugin/SerializationAndDeserialization.fs @@ -9,7 +9,7 @@ open System.Text.Json.Serialization type InnerTypeWithBoth = { [] - Thing : string + Thing : Guid Map : Map ReadOnlyDict : IReadOnlyDictionary Dict : IDictionary diff --git a/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs b/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs index 49431b4..da7a780 100644 --- a/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs +++ b/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs @@ -19,7 +19,7 @@ module TestJsonSerde = let rec innerGen (count : int) : Gen = gen { - let! s = Arb.generate> + let! guid = Arb.generate let! mapKeys = Gen.listOf Arb.generate> let mapKeys = mapKeys |> List.map _.Get |> List.distinct let! mapValues = Gen.listOfLength mapKeys.Length uriGen @@ -59,7 +59,7 @@ module TestJsonSerde = return { - Thing = s.Get + Thing = guid Map = map ReadOnlyDict = readOnlyDict Dict = dict @@ -101,3 +101,23 @@ module TestJsonSerde = true property |> Prop.forAll (Arb.fromGen outerGen) |> Check.QuickThrowOnFailure + + [] + let ``Guids are treated just like strings`` () = + let guidStr = "b1e7496e-6e79-4158-8579-a01de355d3b2" + let guid = Guid.Parse guidStr + + let node = + { + Thing = guid + Map = Map.empty + ReadOnlyDict = readOnlyDict [] + Dict = dict [] + ConcreteDict = Dictionary () + } + |> InnerTypeWithBoth.toJsonNode + + node.ToJsonString () + |> shouldEqual ( + sprintf """{"it\u0027s-a-me":"%s","map":{},"readOnlyDict":{},"dict":{},"concreteDict":{}}""" guidStr + ) diff --git a/WoofWare.Myriad.Plugins/AstHelper.fs b/WoofWare.Myriad.Plugins/AstHelper.fs index 9339fde..02e3a2c 100644 --- a/WoofWare.Myriad.Plugins/AstHelper.fs +++ b/WoofWare.Myriad.Plugins/AstHelper.fs @@ -467,6 +467,15 @@ module internal SynTypePatterns = | _ -> None | _ -> None + let (|Guid|_|) (fieldType : SynType) : unit option = + match fieldType with + | SynType.LongIdent ident -> + match ident.LongIdent |> List.map (fun i -> i.idText) with + | [ "System" ; "Guid" ] + | [ "Guid" ] -> Some () + | _ -> None + | _ -> None + let (|HttpResponseMessage|_|) (fieldType : SynType) : unit option = match fieldType with | SynType.LongIdent ident -> diff --git a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs index 44b1624..6d1c56b 100644 --- a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs @@ -211,6 +211,12 @@ module internal JsonParseGenerator = node |> asValueGetValue propertyName "string" |> SynExpr.pipeThroughFunction (SynExpr.CreateLongIdent (SynLongIdent.Create [ "System" ; "Uri" ])) + | Guid -> + node + |> asValueGetValue propertyName "string" + |> SynExpr.pipeThroughFunction ( + SynExpr.CreateLongIdent (SynLongIdent.Create [ "System" ; "Guid" ; "Parse" ]) + ) | DateTime -> node |> asValueGetValue propertyName "string" diff --git a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs index 8782dd4..eeb0357 100644 --- a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs @@ -43,8 +43,9 @@ module internal JsonSerializeGenerator = | DateTime | NumberType _ | PrimitiveType _ + | Guid | Uri -> - // JsonValue.Create<{type}> + // JsonValue.Create SynExpr.TypeApp ( SynExpr.CreateLongIdent ( SynLongIdent.Create [ "System" ; "Text" ; "Json" ; "Nodes" ; "JsonValue" ; "Create" ]