I’ve searched on internet about my problem.. but I not found a good solution.
I need to get the json showed at the end:
I’ve 2 classes
class Order {
Long id;
Client client;
}
class Client {
Long id;
}
When I serialize Order I get:
[{"id":1,"client":{"id":1}]
But I want instead to obtain:
[{"id":1,"client":1}]
How can i reach this?
Thank you for any solution!!!
Marco
– When a class implements
Serializable, then its object or the object of its Sub-class are made to beSerialized.– Now its the
Fieldsof the Object, Not theObjectitself that is being Serialized.– And the
entire object graphneeds to be serialized, if not the Serialization fails.– So
Clientbeing anObject Reference VariableinOrderClass will get Serialize, and so does itsFieldid.– You canNot Serialize property of a field instead of entire field, but if you want you can prevent
Fieldfrom being serialized usingtransientkeyword.