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

Serializing F# objects with interfaces ignores interface members #1075

Open
kellerd opened this issue Nov 10, 2016 · 0 comments
Open

Serializing F# objects with interfaces ignores interface members #1075

kellerd opened this issue Nov 10, 2016 · 0 comments

Comments

@kellerd
Copy link

kellerd commented Nov 10, 2016

Test Script

#I "../packages/Newtonsoft.Json/lib/net45"
#r "Newtonsoft.Json.dll"
open Newtonsoft.Json
type IFoo = abstract FooMember: int

type IBar =
inherit IFoo
abstract BarMember: int

// Approach 1: Implement IFoo "explicitly".
// In the object browser, you will see both IFoo and IBar as parents of FooBar.
type FooBar =
{Name:string}
interface IFoo with member this.FooMember = 0
interface IBar with member this.BarMember = 0

// Approach 2: Implement IFoo "implicitly" (as part of IBar).
// In the object browser, you will only see IBar as parent of FooBar.
type FooBar2(name : string) =
member x.Name2 = name
interface IBar with
member this.FooMember = 0
member this.BarMember = 0

let one = JsonConvert.SerializeObject({Name="One"})
let two = JsonConvert.SerializeObject(FooBar2("Two"))

Output

val one : string = "{"Name":"One"}"
val two : string = "{"Name2":"Two"}"

Expected output

val one : string = "{"Name":"One", "FooMember":0, "BarMember":0}"
val two : string = "{"Name2":"Two", "FooMember":0, "BarMember":0}"

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

No branches or pull requests

1 participant