Closed Aravind-MJ closed 2 months ago
No. In PHP, that method is the implementation of the JsonSerializable interface and is intended to collect the fields to be encoded when passing the object to json_encode.
To perform the actual serialization, use json_encode.
Ah so I don't have to call that function before passing the object into the json_encode
. I understood that wrong. Gotcha.
In
Questionnaire
, we have list ofitems
. When calling->jsonSerialize
onQuestionnaire
, it returns a\stdClass
object but the values initem
field is an array ofQuestionnaireItem
instances. Shouldn't they also be jsonSerialized? For now I have a helper functionnestedJsonSerialize
that I use for JSON encoding. Not sure about XMLSerialize though.