bvko
Custom JsonConverter to apply to interface or abstract class, anyone ?
// public class ISerilizableStateConverter : JsonConverter <<< I need to write some custom Converter that will when doing
// serializing take Type of implementing class and put it in Json, example ResolveToType:"TestClass1" and when de-serializing
// read that ResolveToType and create instance of that implementing class
// So if i have ISerilizableState currentState i can apply serializing and de-serializing and not get error, atm i get
// recursion error or endelss loop or null xD, anyone already tacked this dragon?
public interface ISerilizableState // can be abstract class too
{
void OnEnter();
void OnExit();
void OnTick();
}
[JsonConverter(typeof(ISerilizableStateConverter))]
public class TestClass1 : ISerilizableState
{
public void OnEnter() { }
public void OnExit() { }
public void OnTick() { UnityEngine.Debug.LogError("Test1"); }
}
[JsonConverter(typeof(ISerilizableStateConverter))]
public class TestClass2 : ISerilizableState
{
public string RandomString = "sss";
public void OnEnter() { }
public void OnExit() { }
public void OnTick() { UnityEngine.Debug.LogError("Test2"); }
}
// public class ISerilizableStateConverter : JsonConverter <<< I need to write some custom Converter that will when doing
// serializing take Type of implementing class and put it in Json, example ResolveToType:"TestClass1" and when de-serializing
// read that ResolveToType and create instance of that implementing class
// So if i have ISerilizableState currentState i can apply serializing and de-serializing and not get error, atm i get
// recursion error or endelss loop or null xD, anyone already tacked this dragon?
public interface ISerilizableState // can be abstract class too
{
void OnEnter();
void OnExit();
void OnTick();
}
[JsonConverter(typeof(ISerilizableStateConverter))]
public class TestClass1 : ISerilizableState
{
public void OnEnter() { }
public void OnExit() { }
public void OnTick() { UnityEngine.Debug.LogError("Test1"); }
}
[JsonConverter(typeof(ISerilizableStateConverter))]
public class TestClass2 : ISerilizableState
{
public string RandomString = "sss";
public void OnEnter() { }
public void OnExit() { }
public void OnTick() { UnityEngine.Debug.LogError("Test2"); }
}
14 replies