@zerkms Shouldn't DTO's be inherently serializable/unserializable through just a function. They're just made up of data with no hidden state, so you can use just a function to do them?
I do this to serialize DTO's as json data to send them to javascript.
@zerkms Possibly you're mistaking the chicken for the egg. If I have a DTO object, I can serialize it with that function. If I have the serialized version, it has encoded in the serialized string what object type it was.
The only problem would come from the database layer, which should understand what it is retrieving.
@zerkms Not quite - that you start with real DTO objects, you can then perform any serialization function on them (and the inverse of that function to a DTO) - but you can have multiple serialization functions for different "serialisation targets" e.g. to Javascript, storing in cache etc.
Yes - DTOs are meant to be totally inspectable from outside the class, they're just a pure transport for data. So you should be able to serialize them from outside the DTO, without having to give the DTO object it's own serialize/deserialize function.
/though asking a Mr Maxell's advice would probably be sensible.