Giter Site home page Giter Site logo

bayatgames / jsonformatter Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 7.0 5.48 MB

Easy, Fast and Lightweight Json Formatter. (Serializer and Deserializer)

C# 100.00%
csharp csharp-library csharp-script formatter json json-parser json-serialization serialization serialization-library serializer unity unity-3d unity-asset unity-scripts unity3d unity3d-plugin

jsonformatter's People

Contributors

hasanbayatme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jsonformatter's Issues

Trying to execute code from example and ge an error

TargetParameterCountException: parameters do not match signature
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:188)
System.Reflection.MonoProperty.GetValue (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:297)
BayatGames.Serialization.Formatters.Json.JsonTextWriter.WriteObject (System.Object value, System.Type type) (at Assets/BayatGames/JsonFormatter/Scripts/JsonTextWriter.cs:218)
BayatGames.Serialization.Formatters.Json.JsonTextWriter.Write (System.Object value) (at Assets/BayatGames/JsonFormatter/Scripts/JsonTextWriter.cs:93)
BayatGames.Serialization.Formatters.Json.JsonFormatter.Serialize (System.IO.TextWriter output, System.Object value) (at Assets/BayatGames/JsonFormatter/Scripts/JsonFormatter.cs:121)
BayatGames.Serialization.Formatters.Json.JsonFormatter.Serialize (System.Object value) (at Assets/BayatGames/JsonFormatter/Scripts/JsonFormatter.cs:98)
BayatGames.Serialization.Formatters.Json.JsonFormatter.SerializeObject (System.Object value) (at Assets/BayatGames/JsonFormatter/Scripts/JsonFormatter.cs:196)
Assets.Editor.DefaultObjects.Save () (at Assets/Editor/DefaultObjects.cs:108)
Assets.Editor.DefaultObjects.OnGUI () (at Assets/Editor/DefaultObjects.cs:62)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)

Various issues and bugfixes

First of all, thank you for this JsonFormatter!

I had some more complex data structures in my game and needed to fix some issues and cornercases.

Perhaps you are interested into adding these to the repository:

  1. No serialization of bool values

Currently, bool values are written as {} and crash on reading.

In JsonTextReader line 105 add: type == typeof(bool) ||
In JsonTextWriter line 84 add: type == typeof(bool) ||

  1. No deserialization of empty dictionaries

The Reader crashes on deserializing an empty dictionary ("{}")

the for loop in line 177 of JsonTextReader should only be executed if there are any values in the dictionary like this:

if (items.Length > 1)
{
for ...
}
  1. No deserialization of custom IEnumerables

When implementing a custom IEnumerable, deserialization fails

In JsonTextWriter line 124 explicitly check for lists and arrays:
else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>) || (type.IsArray))

This should check for the exact same types as the JsonReader to avoid issues on deserialization.

There might be a similar issue with custom IDictionary, but I do not have these in my project.

  1. No deserialization of null values in strings

A null value of a string is read to "ul" due to line 103 in JsonTextReader

I added a null check there:

if("null".Equals(json))
{
    return null;
}
  1. Private attributes are not serialized regardless of [SerializeField]

I tried manually adding [SerializeField] to my private attributes but they are not serialized regardless

Private attributes are only checked in GetField/GetProperty/GetFields/GetProperties if binding flags are set. I set them to: BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance

However, in my project pretty much all private fields within a savegame are to be serialized so I did not check for the [SerializeField] flag either.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.