Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

added Converter #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

added Converter #145

wants to merge 2 commits into from

Conversation

SCullman
Copy link
Contributor

No description provided.

@SCullman SCullman changed the title added Converter #143 added Converter May 19, 2019
@SCullman
Copy link
Contributor Author

adds a converter (build on top of Thoth.Json.Net), handles #143

Copy link
Owner

@MangelMaxime MangelMaxime left a 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()
Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Owner

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)

Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 :-)

@SCullman
Copy link
Contributor Author

I am going to resubmit to https://github.com/thoth-org/Thoth.Json.Net/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants