2

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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.