JsonFX and Polymorphism?

I’m trying to store (readable) data in a text-file as an asset since the class I’m serializing contains many things that Unity itself can’t handle.

A problem is though, that even though everything saves and loads, only the base-type is returned.
I did a lot of searches on the internet to find a solution and I’ve tried everything recommended but alas, the problem still resides.

I’m trying to serialize a class with 2 fields, one int and one Dictionary;

Item is the base class with a large variety of children
I’ve had to convert int to string to allow jsonfx to de-serialize the dictionary.
The following code is used to serialize and de-serialize the data.

public static string FiletoJSON(object T)
    {
        try
        {
            StringBuilder sb = new StringBuilder();

            JsonWriterSettings settings = JsonDataWriter.CreateSettings(false);
            settings.TypeHintName = "__type";

            JsonWriter writer = new JsonWriter(sb, settings);
            writer.Write(T);
            return sb.ToString();
        }
        catch(Exception e)
        {
            Debug.LogWarning(e.InnerException);
            return null;
        }
    }

    public static T JSONtoFile<T>(string JSONString)
    {
        try
        {
            JsonReaderSettings settings = JsonDataReader.CreateSettings(true);
            settings.TypeHintName = "__type";
            using (TextReader textReader = new StringReader(JSONString))
            {
                var jsonReader = new JsonReader(textReader, settings);
                return jsonReader.Deserialize<T>();
            }
        }
        catch (Exception e)
        {
            Debug.LogWarning(e);
            return default(T);
        }
    }

The following is the output of the string.

{
	"__type": "ItemDatabase, Assembly-CSharp",
	
	"DatabaseID": 1,
	
	"ItemList": 
		{
			"1": 
				{
					"__type": "Sniper, Assembly-CSharp",
					"MaxAmountOfItem": 1,
					
					"RangedAttack": 950,
					
					"WeaponObjectID": 3,
					
					"weaponType": "Sniper",
					
					"Accuracy": 100,
					
					"MaxEnergy": 437,
					
					"SkillSlots": null,
					
					"StatusEffects": null,
					
					"EnergyRestorePerTick": 8,
					
					"EnergyRestoreOverTime": true,
					
					"Variance": 30,
					
					"Cooldown": 1,
					
					"Name": "TestSniper",
					
					"Description": "",
					
					"ID": 1,
					
					"Points": 1,
					
					"Tier": 8
				}
		}
}

How can I make sure that JsonFX properly de-serializes my sub-types too?

Note: The purpose of this, is storing several dictionaries filled with supertypes. I’ve managed to accomplish this with a binaryformatter, but there is a noticeable performance reduction compared to using JSON. On top of this, the data in the text file is unreadable.

Never worked with the JsonReader before, but I have worked with the newtonsoft one & I know that supports polymorphism ok.

I had a base class (Message) with a number of derived classes. I found that I couldn’t serilaise a Message polymorphicly, but a Message seemed to work just fine.

As for testing: just write a test script:

void Start()
{
  Soldier s;
  s=new Sniper(){....};
  string str=JsonToString(s);
  Soldier s2=StringToJson(str);
  if (s2 is Sniper)
  {
     Sniper snip=(Sniper)s2;
     Debug.Log(....);
  }
  else
  {
     Debug.Log("Polymorthism issue");
  }
}