Hey I'm trying to use the Unity Json Utility (UnityEngine.JsonUtility) that comes built into the UnityEngine library to serialise a pretty simple object with a single public string field.
My code using the library is pretty straightforward:
var logDTO = new LogDTO();
logDTO.Message = "Unity speaks too!";
var obj = JsonUtility.ToJson(logDTO);
And my object is about as simple as it gets:
[System.Serializable]
public class LogDTO {
public string Message { get; set; }
}
This is the json result.
Expected:
{ Message : "Unity speaks too!" }
Actual:
{}
You can see the whole thing in the following screenshot:
Other Json libraries like JsonFX work as expected, but for some reason JsonUtility doesn't. Anyone come across this or see what I'm doing wrong with here?