When writing custom deserialization code, what's the better practice: a static method that creates an uninitialised object (e.g. using the default constructor) and then performs deserialization, or a constructor that performs deserialization directly?For example, deserializing a Foo:class Foo{    int bar;    this() { }    static Foo fromMyDataFormat(byte[] serializedData)    {        auto foo = new Foo();        foo.bar = /* deserialize bar from serializedData */;        return foo;    }}versusclass Foo{    int bar;    this(byte[] serializedData)    {        bar = /* deserialize bar from serializedData */;    }}What are the pros and cons of both approaches? Are there other options?Only deserialization should be implemented.
Should custom deserialization happen in a constructor or in a static method?
language agnostic;serialization
No, it should not. Serialization is orthogonal to the object and thus should be kept outside. Custom serialization belongs in a customization to a serializer.