0
    public class EntityResultList: List<Model.EntityResult>
    {
        public EntityResultAttribute[] Attributes { get; set; }
    }

if i do serialization with newtonsoft the Property "Attributes" is missing in json text. it seems to be related to de inheritence to a generic list. any ideas how i can fix this? :-(

the serialization is done with this options:

string serializedReply = JsonConvert.SerializeObject(reply, new JsonSerializerSettings
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        TypeNameHandling = TypeNameHandling.All
                    });
wuhi
  • 51
  • 2
  • 2
    Are you 100% sure that *inheriting* from List is correct in this scenario? It [really, really, really looks incorrect](https://stackoverflow.com/questions/21692193/why-not-inherit-from-listt) – Camilo Terevinto Dec 22 '20 at 15:59
  • 1
    It's because JSON has two different types of container -- array and object. Since `EntityResultList` is serialized as an array there's no way to serialize its properties, because only objects have properties. See [JSON serialize properties on class inheriting list](https://stackoverflow.com/a/35439861/3744182) for a more detailed explanation. – dbc Dec 22 '20 at 16:02
  • 1
    Let's assume what you describing is a correct usecase. What exactly are you expecting to get in your string? For lists it should be ```[ item1, item2, …]```, for objects it would be ```{ property1 = ..., property2 = ..., …}```. But here you have a mix of two. – Morse Dec 22 '20 at 16:04
  • 1
    thanks for the quick replies. exactly what i needed :-) i removed the inheritence and added a List-property... – wuhi Dec 22 '20 at 16:06

0 Answers0