Raghuveer
Raghuveer

Reputation: 2637

Hide some public properties in ServiceStack service Request and Response DTO's

I am building some services using ServiceStack, I have a following service

public class FooRequest: IReturn<FooResponse>
    {
        public int FooID { get; set; }
        public decimal Amount { get; set; }
        public string SortColumnName { get; set; }
    }
public class FooResponse 
{
    private List<Payment> payments;
    public FooResponse()
    {
        payments= new List<Payment>();
    }
    public List<Payment> Payments
    {
        get { return payments; }
        set { payments = value; }
    }
}

public class Payment
{
    public int ID { get; set; }
    public string Amount { get; set; }  // Amount is formatted string based on the user language          
    public decimal PaymentAmount{ get; set; } // this is Alias for Amount
}

From above FooResponse, I don't want to show PaymentAmount in response/metadata.

If we make it as normal variable instead of property, it won't be visible in metadata. but that should be a property for other requirement.

Is it possible in ServiceStack to restrict some properties in response DTO?

Upvotes: 2

Views: 2009

Answers (1)

Marcel N.
Marcel N.

Reputation: 13986

Use the IgnoreDataMember attribute on the PaymentAmount property. Last time I checked ServiceStack was using and complying to the default .NET serialization attributes.

Upvotes: 6

Related Questions