ServiceStack.Text AutoMappingUtils ConvertTo Ignores [Default] attribute

Hi,

I’m trying to use the [Default] attribute on a Lookup class.

In Service Model:

public class Lookup
{
    [AutoIncrement]
    [PrimaryKey]
    public int LookupId { get; set; }
    
    public string Name { get; set; }

    public string Description { get; set; }
            
    [Default(typeof(bool), "0")]
    public bool IsDeleted { get; set; }
    
    [Default(typeof(bool), "1")]
    public bool IsCurrentRecord { get; set; }
}

[Route("/lookups", "POST", Summary = "Create a new Lookup with the supplied name and description")]
public class CreateLookup
{
    public string Name { get; set; }
    public string Description { get; set; }
}

In Service:

public Lookup Post(CreateLookup request)
{
    var lookup = request.ConvertTo<Lookup>();
    return lookup;
}

I was expecting when I use a CreateLookup request and then use ConvertTo that the IsDeleted value would be set to false and the IsCurrentRecord would be set to true.

However the IsCurrentRecord is set to false.

Am I missing a JsConfig parameter / POCO attribute or misunderstanding that AutoMapping takes the [Default] attribute into account? If so how do I get the IsCurrentRecord to default to true?

Thanks,
John

The [Default] attribute is only used when creating schemas in RDBMS tables, it has no effect in AutoMapping.

Thanks, appreciate the quick response.

1 Like