1

I want to use ServiceStack JsonSerializer.

I am setting IncludeTypeInfo property true before I serialize my object.And my serialized string contains all type informations like "__type":".Interfacesb,....

When I want to deserialize string that time my interface property null even though I have type information in my serialized string.Is there any other configuration need when deserializing object.

I use two methods JsonSerializer.SerializeToString and JsonSerializer.DeSerializeFromString

Example:

JsConfig.IncludeTypeInfo = true;

Public Class MyObject
{
Public string a{get;set;}
Public interface  b{get;Set;}
}
Joel Harkes
  • 10,975
  • 3
  • 46
  • 65
Bilgehan
  • 1,135
  • 1
  • 14
  • 41

1 Answers1

1

First, the version 4.* is the continued developed version. 3.9 is not actively maintained by anyone.

Test on servicestack.text 4.50

Secondly i don't think this this property was made to de-serialize it back practical objects.

i did the same in 4.50 and it just doesn't deserialize: enter image description here

Alternative solutions

Here you can read what to if you want the types from the json: https://stackoverflow.com/a/21603948/1275832.

When you have the type:

I use the following code as an alternative solution (note its an extension method) as a solution for run-time dynamic types (v4.50):

public static object FromJson(this string json, Type deserializeType)
{
    return typeof(JsonSerializer).GetMethod("DeserializeFromString", BindingFlags.Static)
        .MakeGenericMethod(deserializeType)
        .Invoke(null, new[] { json });
}

and usage as: var object = (MyInterface)jsonString.FromJson(Type.GetType(AssemblyQualifiedNameString));

Community
  • 1
  • 1
Joel Harkes
  • 10,975
  • 3
  • 46
  • 65
  • 1
    I found my problem,I have a readonly property,without set method it isnt deserialized.And second point I change my property type interface to object. – Bilgehan Oct 19 '16 at 07:30