I’m trying to integrate a SimpleXml library in the project I’m working on. Is there a way to serialize models to XML with some fields being optional. Couldn’t figure it out from the documentation.
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.
You should use the Object representation of the types you have defined:
double -> Double
int -> Integer
This allows you to define them as null like so:
Reviewing the documentation, required=false is more for the object de-serialization than for the object serialization. So, you could use the primitive types there, but doing so would require that you use a non-null value during assignment. Upon de-serialization, if your xml does not define latitude, latitude would be given a default init value of 0 instead of null. Just depends upon what behavior you want.
Edit:
Be sure to define the constructor with the Object representations: