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

Exception when serializing type: obj option #6

Open
yuqiu42 opened this issue Feb 7, 2018 · 2 comments
Open

Exception when serializing type: obj option #6

yuqiu42 opened this issue Feb 7, 2018 · 2 comments
Assignees

Comments

@yuqiu42
Copy link

yuqiu42 commented Feb 7, 2018

Sample code

        let l = ["a", (Some (1 :> obj))]
        printfn "json: %s" (l |> Map.ofList |> Json.serialize)

Exception:

Unhandled Exception: System.Exception: Unknown type: Type=Object
   at Vertigo.Json.Internals.NonOption$cont@204(JsonConfig config, Object value, Type t, Unit unitVar)
   at Vertigo.Json.Internals.Serialize.NonOption(JsonConfig config, Type t, Object value, JsonProperty attr)
   at Vertigo.Json.Internals.Serialize.Option(JsonConfig config, Type t, Object o, JsonProperty attr)
   at [email protected](Object o)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@74.DoMoveNext(b& curr)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
   at Vertigo.Json.Internals.Serialize.Map(JsonConfig config, IEnumerable kvps)
   at Vertigo.Json.Json.serialize(Object objekt)
@Tombert Tombert self-assigned this Feb 7, 2018
@Tombert
Copy link
Contributor

Tombert commented Feb 7, 2018

This is not a very high priority bug, but it's a bug nonetheless, will look at this this evening.

@Tombert
Copy link
Contributor

Tombert commented Feb 7, 2018

For anyone stuck on this, a workaround is to cast the entire Option as an obj instead of the internal value:

        let l = ["a", (Some (1) :> obj)]
        printfn "json: %s" (l |> Map.ofList |> Json.serialize)

Hopefully this fixes anyone's problems until I can push a patch.

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

No branches or pull requests

2 participants