Open Closed

deserialize Json, abstract class in ApplicationService #76


0
ioannes created

Hello,

In my ApplicationService I need to deserialize list of objects send from client to concrete classes which inherits abstract class Module.

public ModulesDto
{
public List<Module> {...}
}

public abstract class Module
{...}

public class Module1: Module
{...}

public class Module2: Module
{...}

but I got null.

Is there a way to do it? I found interesting article, and even more interesting comment bellow, how to implement it.

var settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto};

http://www.tomdupont.net/2014/04/deseri ... -with.html

Thanks. :)


2 Answer(s)
  • 0
    hikalkan created

    Hi,

    I assume that you're using application services and dynamic web API layer.

    ABP uses ASP.NET Web API's defult model binding. And as I know this is not possible, at least as default. Because we can not know which class will be used based on properties. If you can find a way of doing it with web API, you can do it with ABP.

    As a workaround, you can send JSON as string and name of the class. Then deserialize it in the C#.

  • 0
    ioannes created

    Thanks for advice! I will use your workaround.