CodeMonkey
CodeMonkey

Reputation: 12424

JsonConvert serialization returns "{}"

I've got a problem in which the following ToJson() method returns a string which is only "{}"

public class GenericRequest
            {
                public enum SupportedCommands
                {
                    REGISTER, LOGIN, LOGOUT
                }

                private SupportedCommands command;
                private String authentication;
                private String password;
                private String email;

                public GenericRequest(SupportedCommands comm, string aut, string pass, string mail)
                {
                    command = comm;
                    authentication = aut;
                    password = pass;
                    email = mail;
                }

                virtual public string ToJson()
                {
                    return JsonConvert.SerializeObject(this);
                }
    }

Got any idea why does the serialization command doesn't serialize the class's members?

Upvotes: 2

Views: 233

Answers (1)

ekolis
ekolis

Reputation: 6776

The fields are private; try using public properties instead (or wrapping the fields in public properties).

Upvotes: 5

Related Questions