Skip to content

Commit

Permalink
Remove net461; switch to net6.0 re #60 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink authored May 5, 2022
1 parent bf96d5b commit 6144527
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 170 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ The `Unreleased` section name is replaced by the expected version of next releas

### Added
### Changed

- `NewtonsoftJson`: Rename `Settings` to `Options` [#60](https://github.com/jet/FsCodec/issues/60) [#76](https://github.com/jet/FsCodec/pull/76)
- Updated build and tests to use `net6.0`, all test package dependencies
- Updated `TypeShape` reference to v `10`, triggering min `FSharp.Core` target moving to `4.5.4`

### Removed

- `net461` support [#60](https://github.com/jet/FsCodec/issues/60) [#76](https://github.com/jet/FsCodec/pull/76)

### Fixed

<a name="2.3.2"></a>
Expand Down
14 changes: 0 additions & 14 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
<PackageLicense>Apache-2.0</PackageLicense>
<Copyright>Copyright © 2016-22</Copyright>

<TestTargetFrameworks>netcoreapp3.1;net461</TestTargetFrameworks>
<!-- avoid fighting with CI images about getting mono to run on MacOSX-->
<TestTargetFrameworks Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' ">net5.0</TestTargetFrameworks>
<ThisDirAbsolute>$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)"))</ThisDirAbsolute>

<!-- Global Project config flags -->
Expand All @@ -21,18 +18,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<!-- disable sourcelink on mono, to workaround https://github.com/dotnet/sourcelink/issues/155 -->
<EnableSourceLink Condition=" '$(OS)' != 'Windows_NT' AND '$(MSBuildRuntimeType)' != 'Core' ">false</EnableSourceLink>

</PropertyGroup>

<ItemGroup> <!-- net461 ref assemblies https://stackoverflow.com/a/57384175/11635 -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
</ItemGroup>

<ItemGroup> <!-- Avoid NRE on mono etc net461 -->
<Content Include="$(ThisDirAbsolute)tests/xunit.runner.json" Condition=" '$(OS)' != 'Windows_NT' AND '$(IsTestProject)' != 'false'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
42 changes: 21 additions & 21 deletions README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
pool:
vmImage: 'macOS-latest'
steps:
- task: UseDotNet@2
displayName: 'Install .NET 6 sdk'
inputs:
packageType: sdk
version: 6.x
- script: dotnet test build.proj
displayName: dotnet test
- task: PublishTestResults@2
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.200",
"rollForward": "latestFeature"
"version": "6.0.202",
"rollForward": "latestMajor"
}
}
9 changes: 4 additions & 5 deletions src/FsCodec.Box/FsCodec.Box.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsTestProject>false</IsTestProject>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
</PropertyGroup>
Expand All @@ -12,12 +11,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="3.1.0" PrivateAssets="All" />

<PackageReference Include="FSharp.Core" Version="4.3.4" />
<PackageReference Include="FSharp.Core" Version="4.5.4" />

<PackageReference Include="TypeShape" Version="8.0.0" />
<PackageReference Include="TypeShape" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/FsCodec.NewtonsoftJson/Codec.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Core =
/// See <a href="https://github.com/eiriktsarpalis/TypeShape/blob/master/tests/TypeShape.Tests/UnionContractTests.fs" /> for example usage.</summary>
type Codec private () =

static let defaultSettings = lazy Settings.Create()
static let defaultSettings = lazy Options.Create()

/// <summary>Generate an <code>IEventCodec</code> using the supplied <c>Newtonsoft.Json</c> <c>settings</c>.<br/>
/// Uses <c>up</c> and <c>down</c> functions to facilitate upconversion/downconversion
Expand All @@ -70,7 +70,7 @@ type Codec private () =
/// a <c>meta</c> object that will be serialized with the same settings (if it's not <c>None</c>)
/// and an Event Creation <c>timestamp</c>.</summary>
down : 'Context option * 'Event -> 'Contract * 'Meta option * Guid * string * string * DateTimeOffset option,
/// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Settings.Default</c></summary>
/// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Options.Default</c></summary>
[<Optional; DefaultParameterValue(null)>] ?settings,
/// <summary>Enables one to fail encoder generation if union contains nullary cases. Defaults to <c>false</c>, i.e. permitting them</summary>
[<Optional; DefaultParameterValue(null)>] ?rejectNullaryCases)
Expand Down Expand Up @@ -116,7 +116,7 @@ type Codec private () =
down : 'Event -> 'Contract * 'Meta option * DateTimeOffset option,
/// <summary>Uses the 'Context passed to the Encode call and the 'Meta emitted by <c>down</c> to a) the final metadata b) the <c>correlationId</c> and c) the correlationId</summary>
mapCausation : 'Context option * 'Meta option -> 'Meta option * Guid * string * string,
/// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Settings.Default</c></summary>
/// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Options.Default</c></summary>
[<Optional; DefaultParameterValue(null)>] ?settings,
/// <summary>Enables one to fail encoder generation if union contains nullary cases. Defaults to <c>false</c>, i.e. permitting them</summary>
[<Optional; DefaultParameterValue(null)>] ?rejectNullaryCases)
Expand All @@ -142,7 +142,7 @@ type Codec private () =
/// a <c>meta</c> object that will be serialized with the same settings (if it's not <c>None</c>)
/// and an Event Creation <c>timestamp</c>.</summary>
down : 'Event -> 'Contract * 'Meta option * DateTimeOffset option,
/// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Settings.Default</c></summary>
/// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Options.Default</c></summary>
[<Optional; DefaultParameterValue(null)>] ?settings,
/// <summary>Enables one to fail encoder generation if union contains nullary cases. Defaults to <c>false</c>, i.e. permitting them</summary>
[<Optional; DefaultParameterValue(null)>] ?rejectNullaryCases)
Expand All @@ -155,7 +155,7 @@ type Codec private () =
/// The Event Type Names are inferred based on either explicit <c>DataMember(Name=</c> Attributes, or (if unspecified) the Discriminated Union Case Name
/// <c>'Union</c> must be tagged with <c>interface TypeShape.UnionContract.IUnionContract</c> to signify this scheme applies.</summary>
static member Create<'Union when 'Union :> TypeShape.UnionContract.IUnionContract>
( /// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Settings.Default</c></summary>
( /// <summary>Configuration to be used by the underlying <c>Newtonsoft.Json</c> Serializer when encoding/decoding. Defaults to same as <c>Options.Default</c></summary>
[<Optional; DefaultParameterValue(null)>] ?settings,
/// <summary>Enables one to fail encoder generation if union contains nullary cases. Defaults to <c>false</c>, i.e. permitting them</summary>
[<Optional; DefaultParameterValue(null)>] ?rejectNullaryCases)
Expand Down
18 changes: 8 additions & 10 deletions src/FsCodec.NewtonsoftJson/FsCodec.NewtonsoftJson.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFramework>netstandard2.0</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
</PropertyGroup>
Expand All @@ -12,23 +11,22 @@
<Compile Include="UnionConverter.fs" />
<Compile Include="TypeSafeEnumConverter.fs" />
<Compile Include="OptionConverter.fs" />
<Compile Include="Settings.fs" />
<Compile Include="Options.fs" />
<Compile Include="Codec.fs" />
<Compile Include="Serdes.fs" />
<Compile Include="VerbatimUtf8Converter.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="3.1.0" PrivateAssets="All" />

<PackageReference Include="FSharp.Core" Version="3.1.2.5" Condition=" '$(TargetFramework)' == 'net461' " />
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netstandard2.0' " />
<PackageReference Include="FSharp.Core" Version="4.5.4" />

<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.2.2" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="TypeShape" Version="8.0.0" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="TypeShape" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open Newtonsoft.Json.Serialization
open System
open System.Runtime.InteropServices

type Settings private () =
type Options private () =

static let defaultConverters : JsonConverter[] = [| OptionConverter() |]

static let def = lazy Settings.Create()
static let def = lazy Options.Create()

/// <summary>Analogous to <c>JsonSerializerOptions.Default</c> - allows for sharing/caching of the default profile as defined by <c>Settings.Create()</c></summary>
/// <summary>Analogous to <c>JsonSerializerOptions.Default</c> - allows for sharing/caching of the default profile as defined by <c>Options.Create()</c></summary>
static member Default : JsonSerializerSettings = def.Value

/// Creates a default set of serializer settings used by Json serialization. When used with no args, same as JsonSerializerSettings.CreateDefault()
Expand Down Expand Up @@ -60,7 +60,7 @@ type Settings private () =
/// Error on missing values (as opposed to letting them just be default-initialized); defaults to false
[<Optional; DefaultParameterValue(null)>] ?errorOnMissing : bool) =

Settings.CreateDefault(
Options.CreateDefault(
converters = (match converters with null | [||] -> defaultConverters | xs -> Array.append defaultConverters xs),
?ignoreNulls = ignoreNulls,
?errorOnMissing = errorOnMissing,
Expand Down
33 changes: 1 addition & 32 deletions src/FsCodec.NewtonsoftJson/Serdes.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
namespace FsCodec.NewtonsoftJson

open FsCodec.NewtonsoftJson
open Newtonsoft.Json
open System.Runtime.InteropServices

/// Serializes to/from strings using the supplied Settings
/// Serializes to/from strings using the supplied JsonSerializerSettings
type Serdes(options : JsonSerializerSettings) =

/// <summary>The <c>JsonSerializerSettings</c> used by this instance.</summary>
Expand All @@ -17,32 +15,3 @@ type Serdes(options : JsonSerializerSettings) =
/// Deserializes value of given type from JSON string.
member x.Deserialize<'T>(json : string) : 'T =
JsonConvert.DeserializeObject<'T>(json, options)

/// Serializes given value to a JSON string.
[<System.Obsolete "Please use non-static Serdes instead">]
static member Serialize<'T>
( /// Value to serialize.
value : 'T,
/// Use indentation when serializing JSON. Defaults to false.
[<Optional; DefaultParameterValue false>] ?indent : bool) : string =
let options = (if indent = Some true then Settings.Create(indent = true) else Settings.Default)
JsonConvert.SerializeObject(value, options)

/// Serializes given value to a JSON string with custom options
[<System.Obsolete "Please use non-static Serdes instead">]
static member Serialize<'T>
( /// Value to serialize.
value : 'T,
/// Settings to use (use other overload to use Settings.Default profile)
settings : JsonSerializerSettings) : string =
JsonConvert.SerializeObject(value, settings)

/// Deserializes value of given type from JSON string.
[<System.Obsolete "Please use non-static Serdes instead">]
static member Deserialize<'T>
( /// Json string to deserialize.
json : string,
/// Settings to use (defaults to Settings.Default profile)
[<Optional; DefaultParameterValue null>] ?settings : JsonSerializerSettings) : 'T =
let settings = match settings with Some x -> x | None -> Settings.Default
JsonConvert.DeserializeObject<'T>(json, settings)
9 changes: 4 additions & 5 deletions src/FsCodec.SystemTextJson/FsCodec.SystemTextJson.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<IsTestProject>false</IsTestProject>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
</PropertyGroup>
Expand All @@ -19,13 +18,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="3.1.0" PrivateAssets="All" />

<PackageReference Include="FSharp.Core" Version="4.3.4" />
<PackageReference Include="FSharp.Core" Version="4.5.4" />

<PackageReference Include="System.Text.Json" Version="6.0.1" />
<PackageReference Include="TypeShape" Version="9.0.0" />
<PackageReference Include="TypeShape" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 0 additions & 30 deletions src/FsCodec.SystemTextJson/Serdes.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace FsCodec.SystemTextJson

open System.Runtime.InteropServices
open System.Text.Json

/// Serializes to/from strings using the supplied Options
Expand All @@ -16,32 +15,3 @@ type Serdes(options : JsonSerializerOptions) =
/// Deserializes value of given type from JSON string.
member x.Deserialize<'T>(json : string) : 'T =
JsonSerializer.Deserialize<'T>(json, options)

/// Serializes given value to a JSON string.
[<System.Obsolete "Please use non-static Serdes instead">]
static member Serialize<'T>
( /// Value to serialize.
value : 'T,
/// Use indentation when serializing JSON. Defaults to false.
[<Optional; DefaultParameterValue false>] ?indent : bool) : string =
let options = (if indent = Some true then Options.Create(indent = true) else Options.Default)
JsonSerializer.Serialize<'T>(value, options)

/// Serializes given value to a JSON string with custom options
[<System.Obsolete "Please use non-static Serdes instead">]
static member Serialize<'T>
( /// Value to serialize.
value : 'T,
/// Options to use (use other overload to use Options.Default profile)
options : JsonSerializerOptions) : string =
JsonSerializer.Serialize<'T>(value, options)

/// Deserializes value of given type from JSON string.
[<System.Obsolete "Please use non-static Serdes instead">]
static member Deserialize<'T>
( /// Json string to deserialize.
json : string,
/// Options to use (defaults to Options.Default profile)
[<Optional; DefaultParameterValue null>] ?options : JsonSerializerOptions) : 'T =
let settings = match options with Some o -> o | None -> Options.Default
JsonSerializer.Deserialize<'T>(json, settings)
10 changes: 4 additions & 6 deletions src/FsCodec/FsCodec.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFramework>netstandard2.0</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
</PropertyGroup>
Expand All @@ -14,11 +13,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="3.1.0" PrivateAssets="All" />

<PackageReference Include="FSharp.Core" Version="3.1.2.5" Condition=" '$(TargetFramework)' == 'net461' " />
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netstandard2.0' " />
<PackageReference Include="FSharp.Core" Version="4.5.4" />
<PackageReference Include="FSharp.UMX" Version="1.0.0" />
</ItemGroup>

Expand Down
10 changes: 5 additions & 5 deletions tests/FsCodec.NewtonsoftJson.Tests/Examples.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Contract =

type Item = { value : string option }
// implies an OptionConverter will be applied
let private serdes = Serdes Settings.Default
let private serdes = Serdes Options.Default
let serialize (x : Item) : string = serdes.Serialize x
let deserialize (json : string) = serdes.Deserialize json

Expand All @@ -32,13 +32,13 @@ module Contract2 =
type TypeThatRequiresMyCustomConverter = { mess : int }
type MyCustomConverter() = inherit JsonPickler<string>() override _.Read(_,_) = "" override _.Write(_,_,_) = ()
type Item = { Value : string option; other : TypeThatRequiresMyCustomConverter }
/// Settings to be used within this contract
/// Options to be used within this contract
// note OptionConverter is also included by default; Value field will write as `"value"`
let private serdes = Settings.Create(MyCustomConverter(), camelCase = true) |> FsCodec.NewtonsoftJson.Serdes
let private serdes = Options.Create(MyCustomConverter(), camelCase = true) |> FsCodec.NewtonsoftJson.Serdes
let serialize (x : Item) = serdes.Serialize x
let deserialize (json : string) : Item = serdes.Deserialize json

let private serdes = Settings.Default |> Serdes
let private serdes = Options.Default |> Serdes
let inline ser x = serdes.Serialize(x)
let inline des<'t> x = serdes.Deserialize<'t>(x)

Expand All @@ -61,7 +61,7 @@ ser { a = "testing"; b = Guid.Empty }
ser Guid.Empty
// "00000000-0000-0000-0000-000000000000"

let serdesWithGuidConverter = Settings.Create(converters = [| GuidConverter() |]) |> Serdes
let serdesWithGuidConverter = Options.Create(converters = [| GuidConverter() |]) |> Serdes
serdesWithGuidConverter.Serialize(Guid.Empty)
// 00000000000000000000000000000000

Expand Down
Loading

0 comments on commit 6144527

Please sign in to comment.