If I create a custom constructor, need I create one with no arguments to use with Gson?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Option 1: Yes, unless you create your own
JsonDeserializerandJsonSerializer, in which case, your serializers can use whatever constructor you want.Specifically, I would advise you to do the extra bit of work if you have other requirements in your classes, such as them being immutable, or if you want to guarantee a minimum state after initialization.
PS: actually, I supose the
JsonDeserializeris enough. Insights anyone?Option 2: (see Eugen’s answer) consider using Genson instead
Option 3: (see Robertiano’s answer) keep the default deserializers and implement InstanceCreator instead