@Override
    public T decode(BsonReader reader, DecoderContext decoderContext) {
        T instance = null;
        Object[] constructorValues = null;
        try {
            Constructor<T> constructor = entity.constructor();
            if (constructor.getParameterCount() == 0) {
                instance = constructor.newInstance();
                initInstance(instance, reader, decoderContext);
                return instance;
            } else {
                constructorValues = parseCtorValues(reader, decoderContext);
                return constructor.newInstance(constructorValues);
            }
        } catch (Exception e) {
            throw new DeserializationException(
                    "Failed to decode the current Bson into the entity of the class: "
                            + entity.entityClass()
                                    .getName()
                            + ", instance: "
                            + instance
                            + ", constructor arguments: "
                            + Arrays.toString(constructorValues),
                    e);
        }
    }
Compared to {@link EntityCodec#encodeValue}, this method encodes null fields because we need
to overwrite existing fields to null if these fields are not specified in the entity for our
use cases.
turms-server-common/src/main/java/im/turms/server/common/storage/mongo/codec/EntityCodec.java