rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
230 stars 29 forks source link

Negative enum Values #223

Closed cubed-it closed 5 years ago

cubed-it commented 5 years ago

Hey there, unfortunately I found a new problem with the current version. Negative enum values cannot be deserialized when using useenumstrings = false.

Here is a simple sample:

   class Program
   {
      static void Main(string[] args)
      {
         NetJSON.NetJSONSettings.CurrentSettings.UseEnumString = false;
         var content = NetJSON.NetJSON.Serialize(new TestA() { EnumAProp = EnumA.ValA });
         var obj = NetJSON.NetJSON.Deserialize<TestA>(content);
      }
   }

   public enum EnumA
   {
      ValA= -1
   }

   public class TestA
   {
      public EnumA EnumAProp { get; set; }
   }
System.ArgumentException: "Must specify valid information for parsing in the string."
   at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at NetJSON.Internals.SerializerUtilities.FlagStringToEnum[T](String value)
   at SetTestA(Char* , Int32& , TestA , String , NetJSONSettings )
   at CreateClassOrDictTestA(Char* , Int32& , NetJSONSettings )
   at ReadTestA(String , NetJSONSettings )
   at DeserializeValue(String )
   at NetJsonTest.Program.Main(String[] args)
rpgmaker commented 5 years ago

Thanks I will look into it.

cubed-it commented 5 years ago

Can you roughly estimate when you will find the time? Would be helpful for my planning. Thanks!

rpgmaker commented 5 years ago

It is resolved now. Should be available in nuget.org shortly. I just published it as 1.3.1

https://www.nuget.org/packages/NetJSON/

cubed-it commented 5 years ago

Great, thank you very much!!