Skip to content

Conversation

friuns2
Copy link

@friuns2 friuns2 commented Nov 19, 2017

Instead of converting string to object, now it can convert any known type to object

here is an example with result {"$types":{"ConsoleApp8.Test":"1"},"$type":"1","custom":3}

using System;
using System.Diagnostics;
using System.IO;
using fastJSON;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            JSON.RegisterCustomType<CustomType, int>(a => a.value, a => new CustomType() { value = a });

            var json = Serializer.Serialize(new Test() { custom = new CustomType() { value = 3 } });
            Console.WriteLine(json);
            var t = Serializer.Deserialize<Test>(json);
            Debug.Assert(t.custom.value == 3);

            Console.ReadLine();
        }
    }
    public struct CustomType
    {
        public int value;
    }
    public class Test
    {
        public CustomType custom = new CustomType();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant