Skip to content

Plug-and-play solution adding custom converters for unity types to Newstonsoft Json

Notifications You must be signed in to change notification settings

AbandonedCrypt/unity-json-converters

Repository files navigation

Unity Json.NET Converters

A drop-in solution providing custom converters for Unity types, no configuration required.

The problem

Newtonsoft Json, which has been officially supported as a Unity package as com.unity.nuget.newtonsoft-json, has trouble serializing most native Unity types such as Color, Vector2 , Vector3 and many more. This is due to self-references in the struct types Unity uses, which runs Json.NET into an infinite serialization loop.

The solution

This package adds custom converters for these Unity types into your project and automatically adds them to the default configuration of Newtonsoft Json in both editor and runtime. No configuration required - plug and play.

Installation

  1. In your package manager (Window > Package Manager) choose the +.
  2. Select "Add from git URL"
  3. Enter https://github.com/AbandonedCrypt/unity-json-converters.git and go.
  4. You are done and ready to de-/serialize

Supported Unity types

Currently only the following are supported, but with time, all will be added.

  • Color
  • Vector2
  • Vector3
  • Vector4

What if i want to override a specific converter?

You can do so by modifying the default settings in your project and adding the converter using the OverwriteAll extension method on the JsonSerializerSettings.Converters collection. It does not matter if that modification gets executed before or after this package.

Why this one?

Its stupidly simple. Even a beginner could maintain a fork of this, were I to stop doing so.

About

Plug-and-play solution adding custom converters for unity types to Newstonsoft Json

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages