In my current work, we need to serialize some data and use it later. Our data is in this format:
<resources>
<style name="Person">
<item name="name">name</item>
<item name="age">32</item>
</style>
<style name="Student" parent="Person">
<item name="course">course</item>
</style>
</resources>
We need to parse these data frequently.
Can we do something similar in json? Apart from xml and json, is there any other data structure to support inheritance better? And what is the best way to parse this parent-child relationship data?
Update:
I like the idea of @Ipad1gs
. I just wanted to clear few more things
in xml, we can extend this to and even we can override
things like the name.
<resources>
<style name="Person">
<item name="name">name</item>
<item name="age">32</item>
</style>
<style name="Student" parent="Person">
<item name="course">course</item>
</style>
<style name="Employee" parent="Person">
<item name="name">employee name</item>
<item name="department">department</item>
</style>
</resources>
How can we do the similar thing in json using composition?
Person
, while at the same time there is anEmployee
and aStudent
. You have at least 2Person
instances, or the object you are serialising is inheriting both (and thereforePerson
,Employee
andStudent
are interfaces, so the implementing object only needs one value forname
) – Caleth Jun 8 '18 at 12:08