0

I have this class:

<TypeConverter(GetType(ExpandableObjectConverter))>
Public Class StyleItem
    Public Property Font As Font = Nothing
    Public Property ForeColor As Color = Color.Black
    Public Property BackColor As Color = Color.Black
    Public Property CodeCase As ScintillaNET.StyleCase = Nothing
End Class

And I serialize it like this:

My.Computer.FileSystem.WriteAllText(path, JsonConvert.SerializeObject(obj), False)

However, The serialized file only contains this:

{"SDefault":"ExtremeStudio.StyleItem","SInteger":"ExtremeStudio.StyleItem","SString":"ExtremeStudio.StyleItem","SSymbols":"ExtremeStudio.StyleItem","SSlComments":"ExtremeStudio.StyleItem","SMlComments":"ExtremeStudio.StyleItem","SPawnDoc":"ExtremeStudio.StyleItem","SPawnPre":"ExtremeStudio.StyleItem","SPawnKeys":"ExtremeStudio.StyleItem","SFunctions":"ExtremeStudio.StyleItem","SPublics":"ExtremeStudio.StyleItem","SStocks":"ExtremeStudio.StyleItem","SNatives":"ExtremeStudio.StyleItem","SDefines":"ExtremeStudio.StyleItem","SMacros":"ExtremeStudio.StyleItem","SEnums":"ExtremeStudio.StyleItem","SGlobalVars":"ExtremeStudio.StyleItem"}

So basically, The object is serialized without its child objects, Why is that ? How to make it to serialize child objects as well ?

Thanks in advanced.

Ahmad45123
  • 402
  • 1
  • 4
  • 15
  • Json.NET will use the type converter to serialize your class if one is present. Either remove it or use the answer from [Newtonsoft.JSON cannot convert model with TypeConverter attribute](https://stackoverflow.com/questions/31325866/newtonsoft-json-cannot-convert-model-with-typeconverter-attribute). – dbc Apr 07 '16 at 22:56
  • Yeah noticed that but the problem is that I need it to be able to make it work in a PropertyGrid. – Ahmad45123 Apr 07 '16 at 22:59
  • I will try the answer there. – Ahmad45123 Apr 07 '16 at 23:01
  • Then use `[JsonConverter(typeof(NoTypeConverterJsonConverter))]` from the [linked answer](https://stackoverflow.com/questions/31325866/newtonsoft-json-cannot-convert-model-with-typeconverter-attribute). – dbc Apr 07 '16 at 23:01
  • 1
    Yep, That worked great :) – Ahmad45123 Apr 07 '16 at 23:08
  • Answer the question. – Ahmad45123 Apr 07 '16 at 23:08
  • I marked your question as a [duplicate](https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled) since the answer from https://stackoverflow.com/questions/31325866/newtonsoft-json-cannot-convert-model-with-typeconverter-attribute precisely answered yours as well. That doesn't imply your question is bad in any way, since the same basic problem can arise in different contexts and so question searches don't always turn up the needed answer. If you want, you can vote that answer up or down. – dbc Apr 07 '16 at 23:13
  • Okay great, Anything that I can for this question ?.. Like close it ?.. I am a bit new. – Ahmad45123 Apr 07 '16 at 23:27
  • No need to delete it once it's marked as a dupe. Duplicates can be useful for people searching for answers. – dbc Apr 07 '16 at 23:30

0 Answers0