re-implemented TypeAdapter using factory pattern