Skip to content
This repository was archived by the owner on May 16, 2022. It is now read-only.

Class inheritance not supported in deserialization? #43

Closed
LordDevil1980 opened this issue Jan 28, 2018 · 6 comments
Closed

Class inheritance not supported in deserialization? #43

LordDevil1980 opened this issue Jan 28, 2018 · 6 comments

Comments

@LordDevil1980
Copy link

LordDevil1980 commented Jan 28, 2018

Hey there :)

I was trying to switch over from Json.NET to your utf8Json.

But I found out that it does not support inheritance of classes?

Example:

public abstract class JsonDBItem
    {
        public int ID { get { return _id; } }
        private int _id = -1;
    }

   public class Card: JsonDBItem
    {
        public string Name { get { return name; } }
        private string name = 0;
    }

Json:
"_id": 1,
"name": "DummyName"

I have AllowPrivate set to true - so the Json file will deserialize the name, but not the properties from the inherited class JsonDBItem -> ID is still empty - in Json.NET this worked. Any chance to make this possible in utf8json?

Thanks alot,
Oliver

@neuecc
Copy link
Owner

neuecc commented Jan 30, 2018

thanks, this is related to MessagePack-CSharp/MessagePack-CSharp#174
currently does not search base type's private member.
I'll fix it.

@neuecc
Copy link
Owner

neuecc commented Jan 30, 2018

I've uploaded 1.3.7 that includes this fix, please try it.

@LordDevil1980
Copy link
Author

LordDevil1980 commented Jan 30, 2018

Oh thats great thanks so much neuecc !! Now I should be able to switch over from old Json.net library to yours 👍

@neuecc neuecc closed this as completed Feb 3, 2018
@TylerAP
Copy link

TylerAP commented Mar 20, 2019

I have v1.3.7 and I have this issue with interface inheritance, the inherited interface has properties that don't get serialized...
I'm using Moq to create a mocked ISomeInterface that inherits from IBaseInterface, then calling JsonSerializer.NonGeneric.Serialize(typeof(ISomeInterface), obj) ... it only serializes ISomeInterface's properties, not IBaseInterface's.

@TylerAP
Copy link

TylerAP commented Mar 20, 2019

I'll create a separate issue for this, I see the problem in the commit that adds this for 1.3.7; you're checking BaseType but not interfaces for public properties...

@TylerAP
Copy link

TylerAP commented Mar 20, 2019

Linked to #81

gordrs pushed a commit to Cryptisk/Utf8Json that referenced this issue Dec 20, 2020
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

3 participants