Converts a field value to the appropriate type based on the field type.