This project has moved and is read-only. For the latest updates, please go here.

Getters & Setters

Nov 10, 2009 at 9:28 PM

Can we serial objects if we are not using properties and are using getter / setter pairs instead



        /// <summary>Answer the name of the Group.</summary>
        public virtual String getName()

        /// <summary>Set the name of the Group.</summary>
        public virtual void setName(String name)
   = name;

This is a port from another language and I would prefer not to have to rewrite all of these as properties

Thanks in advance.



Nov 10, 2009 at 10:47 PM



Nov 11, 2009 at 12:20 PM
Edited Nov 11, 2009 at 12:30 PM

There is no way to create a custom serializer for a class or can this somehow be accomplished via a ContractResolver.

If not what are my options here (hopefully without rewriting all these classes)

Let me add that I am using ExtJS which utilizes your library for JSON serialization and am not sure at this point in time if I even have the option to replace my JSON serialization with an alternative mechanism and am looking for the simplest and easiest mechanism to get my JSON in the form expected by ExtJS.

I could always write a bunch of UI wrapper / adapter classes (or even dynamic proxies) but that solution probably isn't going to be all the clean in the long run.

Thanks in advance.


Nov 13, 2009 at 2:29 AM

Hmmm you might be able to do it with a custom ContractResolver.

The latest version of the Json.NET source code on CodePlex is no longer tied to a PropertyInfo for getting and setting values. You could create an IValueGetter and IValueSetter that works over methods.

Possible but complicated if you're not familiar with IContractResolver.