Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot serialized higher order type when type is boxed #32

Open
bruno-cadorette opened this issue Mar 30, 2020 · 3 comments · May be fixed by #33
Open

Cannot serialized higher order type when type is boxed #32

bruno-cadorette opened this issue Mar 30, 2020 · 3 comments · May be fixed by #33

Comments

@bruno-cadorette
Copy link

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.

@MangelMaxime
Copy link
Contributor

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.

@bruno-cadorette
Copy link
Author

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

@MangelMaxime
Copy link
Contributor

This indeed looks like the right direction

@bruno-cadorette bruno-cadorette linked a pull request Mar 31, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants