diff --git a/ConsumePlugin/GeneratedSerde.fs b/ConsumePlugin/GeneratedSerde.fs index 622b78a..7a1d8c5 100644 --- a/ConsumePlugin/GeneratedSerde.fs +++ b/ConsumePlugin/GeneratedSerde.fs @@ -210,6 +210,8 @@ module JsonRecordTypeWithBothJsonSerializeExtension = |> (fun field -> field.ToString "o" |> System.Text.Json.Nodes.JsonValue.Create)) ) + node.Add ("unit", (input.Unit |> (fun value -> System.Text.Json.Nodes.JsonObject ()))) + node :> _ namespace ConsumePlugin @@ -478,6 +480,8 @@ module JsonRecordTypeWithBothJsonParseExtension = /// Parse from a JSON node. static member jsonParse (node : System.Text.Json.Nodes.JsonNode) : JsonRecordTypeWithBoth = + let arg_21 = () + let arg_20 = (match node.["timestamp"] with | null -> @@ -759,6 +763,7 @@ module JsonRecordTypeWithBothJsonParseExtension = IntMeasureNullable = arg_18 Enum = arg_19 Timestamp = arg_20 + Unit = arg_21 } namespace ConsumePlugin diff --git a/ConsumePlugin/SerializationAndDeserialization.fs b/ConsumePlugin/SerializationAndDeserialization.fs index 66365ef..d06ad91 100644 --- a/ConsumePlugin/SerializationAndDeserialization.fs +++ b/ConsumePlugin/SerializationAndDeserialization.fs @@ -50,6 +50,7 @@ type JsonRecordTypeWithBoth = IntMeasureNullable : int Nullable Enum : SomeEnum Timestamp : DateTimeOffset + Unit : unit } [] diff --git a/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs b/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs index 3c6a106..f78284f 100644 --- a/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs +++ b/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs @@ -117,6 +117,7 @@ module TestJsonSerde = IntMeasureNullable = intMeasureNullable Enum = enum someEnum Timestamp = timestamp + Unit = () } } @@ -168,6 +169,7 @@ module TestJsonSerde = IntMeasureNullable = Nullable -883 Enum = enum 1 Timestamp = DateTimeOffset (2024, 07, 01, 17, 54, 00, TimeSpan.FromHours 1.0) + Unit = () } let expected = @@ -198,7 +200,8 @@ module TestJsonSerde = "intMeasureOption": 981, "intMeasureNullable": -883, "enum": 1, - "timestamp": "2024-07-01T17:54:00.0000000\u002B01:00" + "timestamp": "2024-07-01T17:54:00.0000000\u002B01:00", + "unit": {} } """ |> fun s -> s.ToCharArray () diff --git a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs index 764eab7..a06c942 100644 --- a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs @@ -280,6 +280,7 @@ module internal JsonParseGenerator = parseNumberType options propertyName node primType |> SynExpr.pipeThroughFunction (Measure.getLanguagePrimitivesMeasure primType) | JsonNode -> node + | Unit -> SynExpr.CreateConst () | _ -> // Let's just hope that we've also got our own type annotation! let typeName = diff --git a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs index a9181f9..d6c72f5 100644 --- a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs @@ -147,6 +147,12 @@ module internal JsonSerializeGenerator = |> SynExpr.createLambda "field" |> fun e -> e, false | JsonNode -> SynExpr.createIdent "id", true + | Unit -> + SynExpr.createLambda + "value" + (SynExpr.createLongIdent [ "System" ; "Text" ; "Json" ; "Nodes" ; "JsonObject" ] + |> SynExpr.applyTo (SynExpr.CreateConst ())), + false | _ -> // {type}.toJsonNode let typeName = diff --git a/WoofWare.Myriad.Plugins/SynExpr/Ident.fs b/WoofWare.Myriad.Plugins/SynExpr/Ident.fs index e054b9b..7befa00 100644 --- a/WoofWare.Myriad.Plugins/SynExpr/Ident.fs +++ b/WoofWare.Myriad.Plugins/SynExpr/Ident.fs @@ -16,6 +16,7 @@ module internal Ident = let createSanitisedParamName (s : string) = match s with | "type" -> create "type'" + | "private" -> create "private'" | _ -> let result = StringBuilder () diff --git a/WoofWare.Myriad.Plugins/SynExpr/SynType.fs b/WoofWare.Myriad.Plugins/SynExpr/SynType.fs index fcef6b9..3fb417d 100644 --- a/WoofWare.Myriad.Plugins/SynExpr/SynType.fs +++ b/WoofWare.Myriad.Plugins/SynExpr/SynType.fs @@ -193,6 +193,17 @@ module internal SynTypePatterns = | _ -> None | _ -> None + let (|Unit|_|) (fieldType : SynType) : unit option = + match fieldType with + | SynType.LongIdent (SynLongIdent.SynLongIdent (ident, _, _)) -> + match ident |> List.map (fun i -> i.idText.ToLowerInvariant ()) with + | [ "microsoft" ; "fsharp" ; "core" ; "unit" ] + | [ "fsharp" ; "core" ; "unit" ] + | [ "core" ; "unit" ] + | [ "unit" ] -> Some () + | _ -> None + | _ -> None + let (|DateOnly|_|) (fieldType : SynType) = match fieldType with | SynType.LongIdent (SynLongIdent.SynLongIdent (ident, _, _)) ->