-
Notifications
You must be signed in to change notification settings - Fork 32
added Converter #145
base: master
Are you sure you want to change the base?
added Converter #145
Conversation
adds a converter (build on top of Thoth.Json.Net), handles #143 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR however this is not the right repository to contribute to.
Could you please send it to https://github.com/thoth-org/Thoth.Json.Net/?
I didn't mark yet this repo as read-only by lack of time. But I have good hopes to do it this week or the next one.
override __.CanConvert(t) = true | ||
|
||
override __.WriteJson(writer, value, _) = | ||
let t = value.GetType() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fails if value
is None
. See for the solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.
If I write override __.WriteJson(writer, (value : 'T), _) =
, value must be an object and can't be a value type anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MangelMaxime , please ignore last comment. the value must be an obj, otherwise it cannnot be represented as Json. And for the very same reason the value cannot be simply None
. Simplest value should be ``[| None |].
However, it still doesn't work . If code is changed to
override __.WriteJson(writer, (value:'t), _) =
let encoder = Encode.Auto.generateEncoderCached<'t>(?isCamelCase=isCamelCase, ?extra=extra)
(encoder value).WriteTo(writer)
writer.Flush()
WriteTo fails in tests with System.ArgumentException: "Could not determine JSON object type for type Record9."
writer.Flush() | ||
|
||
override __.ReadJson(reader, t, _, _) = | ||
let decoder = Decode.Auto.generateDecoderCachedByType(t, ?isCamelCase=isCamelCase, ?extra=extra) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the version which use the generic type here too (same as above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it is not like above. t is of System.Type (and not generic as the value)
override __.ReadJson(reader, t, _, _) = | ||
let decoder = Decode.Auto.generateDecoderCachedByType(t, ?isCamelCase=isCamelCase, ?extra=extra) | ||
let json = JObject.Load(reader).ToString() | ||
Decode.fromString decoder json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use Decode.unsafeFromString
instead of manually handling the Result
type
@@ -0,0 +1,18 @@ | |||
namespace Thoth.Json.WebApi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this belongs to Thoth.Json.Net
You are adding Microsoft.AspNet.WebApi
as a dependencies of Thoth.Json.Net which is not needed. It should be in the future a separate package like Thoth.Json.Giraffe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new package Thoth.Json.WepApi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thoth.Json,Giraffe is now also in its own repository :-)
I am going to resubmit to https://github.com/thoth-org/Thoth.Json.Net/ |
No description provided.