mirror of
https://gitea.tendokyu.moe/beerpsi/Rizu.git
synced 2024-11-23 23:01:01 +01:00
3ed7191acf
When running via BepInEx, Unity's JsonUtility produces and reads empty documents. As a bit of a hacky fix, this builds using System.Text.Json. granted, this pulls new deps in. All of the deps listed in the csproj will need to be included in the install package for BepInEx. Reviewed-on: https://gitea.tendokyu.moe/beerpsi/Rizu/pulls/1 Co-authored-by: Adele Reed <virepri2k@gmail.com> Co-committed-by: Adele Reed <virepri2k@gmail.com>
39 lines
874 B
C#
39 lines
874 B
C#
namespace Rizu.Core;
|
|
|
|
/*
|
|
* JsonShim creates a single place that JSON APIs get called from, to avoid having to manually write precompiler directives every time.
|
|
* Never call a JSON package directly, always call via JsonShim.
|
|
*/
|
|
|
|
#if MONOMOD
|
|
using UnityEngine;
|
|
using System;
|
|
#else
|
|
using System.Text.Json;
|
|
#endif
|
|
|
|
public class JsonShim
|
|
{
|
|
public static string Serialize(object Target)
|
|
{
|
|
#if MONOMOD
|
|
return JsonUtility.ToJson(Target);
|
|
#else
|
|
return JsonSerializer.Serialize(Target);
|
|
#endif
|
|
}
|
|
|
|
public static T Deserialize<T>(string data)
|
|
{
|
|
#if MONOMOD
|
|
return JsonUtility.FromJson<T>(data);
|
|
#else
|
|
return JsonSerializer.Deserialize<T>(data);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#if MONOMOD
|
|
[AttributeUsage(AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple = false)]
|
|
public class JsonIncludeAttribute : Attribute { }
|
|
#endif |