Cannot serialized higher order type when type is boxed
This code throws System.ArgumentException: 'Could not determine JSON object type for type Program+MyRecord.'
type MyRecord = {
Field1 : string
Field2 : int
Field3 : bool
}
type Wrapper<'a> = {
Id: string
Config: 'a
}
let myObject = {
Id = "test test test";
Config = (box {Field1 = "hi"; Field2 = 2; Field3 = true })
}
let result = JsonConvert.SerializeObject(myObject, Converters.Converter())
If we remove the box, the serialization works but sadly in my case I cannot avoid it.
Hello,
at first, I would have say that boxing the type would prevent us to access the "real" type info. But the error seems to know that it's the type Program+MyRecord that need to be accessed.
Will have to dig more in it.
Thanks!
Line 416 of Encode.fs it call autoEncoder with fi.PropertyType which returns System.Object, which ultimately create this encoder: boxEncoder(fun (v: obj) -> JValue(v) :> JsonValue)
I think this happen because the type of the Config field when we box it is object.
I might have a fix
This indeed looks like the right direction