Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible RegisterCustomType #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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