Skip to content

Commit

Permalink
Release version 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Mar 4, 2020
1 parent a28ac82 commit 336fede
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## 4.0.0 - 2020-03-04

* Update to Thoth.Json.Net v4

## 3.2.0

* Avoid "Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true." (by @MaxDeg)
Expand Down
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ storage: none

nuget FSharp.Core redirects:force, content:none
nuget Giraffe >= 3.6 lowest_matching:true
nuget Thoth.Json.Net
nuget Thoth.Json.Net ~> 4
nuget Expecto
nuget Microsoft.AspNetCore.TestHost
nuget Microsoft.NET.Test.Sdk
Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ NUGET
FSharp.Core (>= 4.1.17) - restriction: || (&& (>= net45) (< net46) (< netstandard1.6)) (&& (< net45) (>= netstandard1.6)) (&& (>= net46) (< netstandard1.6)) (>= net47)
NETStandard.Library (>= 1.6.1) - restriction: && (< net45) (>= netstandard1.6)
System.ValueTuple (>= 4.4) - restriction: || (&& (>= net45) (< net46) (< netstandard1.6)) (&& (< net45) (>= netstandard1.6)) (&& (>= net46) (< netstandard1.6)) (>= net47)
Thoth.Json.Net (3.6)
Thoth.Json.Net (4.0)
Fable.Core (>= 3.0 < 4.0) - restriction: && (< net46) (>= netstandard2.0)
FSharp.Core (>= 4.6.2) - restriction: || (>= net46) (>= netstandard2.0)
Newtonsoft.Json (>= 11.0.2) - restriction: || (>= net46) (>= netstandard2.0)
Expand Down
2 changes: 1 addition & 1 deletion src/Thoth.Json.Giraffe.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RepositoryUrl>https://github.com/MangelMaxime/Thoth</RepositoryUrl>
<PackageTags>fsharp;json;Giraffe;ASP.NET;Core</PackageTags>
<Authors>Maxime Mangel</Authors>
<Version>3.2.0</Version>
<Version>4.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
Expand Down
14 changes: 7 additions & 7 deletions src/ThothSerializer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open Giraffe
open Giraffe.Serialization.Json
open Thoth.Json.Net

type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField : bool) =
type ThothSerializer (?caseStrategy : CaseStrategy, ?extra : ExtraCoders, ?skipNullField : bool) =
static let Utf8EncodingWithoutBom = new UTF8Encoding(false)
static let DefaultBufferSize = 1024

Expand Down Expand Up @@ -78,17 +78,17 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField
interface IJsonSerializer with
member __.SerializeToString (o : 'T) =
let t = if isNull <| box o then typeof<'T> else o.GetType()
let encoder = Encode.Auto.LowLevel.generateEncoderCached(t, ?isCamelCase=isCamelCase, ?extra=extra, ?skipNullField=skipNullField)
let encoder = Encode.Auto.LowLevel.generateEncoderCached(t, ?caseStrategy=caseStrategy, ?extra=extra, ?skipNullField=skipNullField)
encoder o |> Encode.toString 0

member __.Deserialize<'T> (json : string) =
let decoder = Decode.Auto.generateDecoderCached<'T>(?isCamelCase=isCamelCase, ?extra=extra)
let decoder = Decode.Auto.generateDecoderCached<'T>(?caseStrategy=caseStrategy, ?extra=extra)
match Decode.fromString decoder json with
| Ok x -> x
| Error er -> failwith er

member __.Deserialize<'T> (bytes : byte[]) =
let decoder = Decode.Auto.generateDecoderCached<'T>(?isCamelCase=isCamelCase, ?extra=extra)
let decoder = Decode.Auto.generateDecoderCached<'T>(?caseStrategy=caseStrategy, ?extra=extra)
use stream = new MemoryStream(bytes)
use streamReader = new StreamReader(stream)
use jsonReader = new JsonTextReader(streamReader)
Expand All @@ -98,7 +98,7 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField
| Error er -> failwith er

member __.DeserializeAsync<'T> (stream : Stream) = task {
let decoder = Decode.Auto.generateDecoderCached<'T>(?isCamelCase=isCamelCase, ?extra=extra)
let decoder = Decode.Auto.generateDecoderCached<'T>(?caseStrategy=caseStrategy, ?extra=extra)
use streamReader = new StreamReader(stream)
use jsonReader = new JsonTextReader(streamReader)
let! json = JValue.ReadFromAsync jsonReader
Expand All @@ -110,7 +110,7 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField

member __.SerializeToBytes<'T>(o : 'T) : byte array =
let t = if isNull <| box o then typeof<'T> else o.GetType()
let encoder = Encode.Auto.LowLevel.generateEncoderCached(t, ?isCamelCase=isCamelCase, ?extra=extra, ?skipNullField=skipNullField)
let encoder = Encode.Auto.LowLevel.generateEncoderCached(t, ?caseStrategy=caseStrategy, ?extra=extra, ?skipNullField=skipNullField)
// TODO: Would it help to create a pool of buffers for the memory stream?
use stream = new MemoryStream()
use writer = new StreamWriter(stream, Utf8EncodingWithoutBom, DefaultBufferSize)
Expand All @@ -127,7 +127,7 @@ type ThothSerializer (?isCamelCase : bool, ?extra : ExtraCoders, ?skipNullField
upcast task {
use streamWriter = new System.IO.StreamWriter(stream, Utf8EncodingWithoutBom, DefaultBufferSize, true)
use jsonWriter = new JsonTextWriter(streamWriter)
let encoder = Encode.Auto.generateEncoderCached<'T>(?isCamelCase=isCamelCase, ?extra=extra, ?skipNullField=skipNullField)
let encoder = Encode.Auto.generateEncoderCached<'T>(?caseStrategy=caseStrategy, ?extra=extra, ?skipNullField=skipNullField)
do! (encoder o).WriteToAsync(jsonWriter)
do! jsonWriter.FlushAsync()
}

0 comments on commit 336fede

Please sign in to comment.