Skip to content

Wrong type for Book.Author ("Persona" become an "Organization") after deserialization #39

@radetskyi

Description

@radetskyi

Author deserialization issue

Just run into situation:

for Book I have a list of Author type of Person

...
"author": [
        {
            "@type": "Person",
            "name": "SomeName",
            "description": "SomeDescription.md",
            "image": "SomeImage",
            "url": "https://someUrl.me",
            "email": "someemail@gmail.com",
            "jobTitle": "CEO SomeCompany Solutions"
        },
        {
            "@type": "Person",
            "name": "Иван Васильевич",
            "image": "Images/Иван Васильевич.jpg",
            "email": "car.kreml@yandex.ru",
            "jobTitle": "просто Царь"
        }
    ]
...

the way I`m deserialize:

public static Book GetMetadata(string path)
        {
            var file = Path.Combine(path, FileNames.Metadata);
            if (File.Exists(file))
            {
                var json = File.ReadAllText(file);
                Book bookMetadata = JsonConvert.DeserializeObject<Book>(json) as Book;
                return bookMetadata;
            }
            else
                throw new ArgumentNullException("Metadata file is missing.");
        }

but after deserialization of my "schema.json" into c# class I got field "Author" type of Organization. Any other fields like "JobTitle" are ignored.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues describing a bug or pull requests fixing a bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions