1

I have the following endpoint:

        public List<SubBranch> Get(GetSubBranch request)
        {
            SubBranch subBranch = new SubBranch();
            subBranch.BranchId = 1;
            subBranch.Addresses = new List<SubBranchAddress>();
            subBranch.Addresses.Add(new SubBranchAddress { AddressType = AddressType.Postal, City = "A" });
            subBranch.Addresses.Add(new SubBranchAddress { AddressType = AddressType.Test, City = "B" });
            subBranch.Addresses.Add(new SubBranchAddress { AddressType = AddressType.Street, City = "C" });
            return new List<SubBranch> { subBranch };
        }

Here is the model:

    public class SubBranch
    {
        public int BranchId { get; set; }
        public List<SubBranchAddress> Addresses { get; set; }
    }
    public class SubBranchAddress
    {        
        public string City { get; set; }
        public AddressType AddressType { get; set; }
    }

    public enum AddressType
    {
        Test,
        Street,
        Postal        
    }

This is providing the following JSON response:

[
  {
    "BranchId": 1,
    "Addresses": [
      {
        "City": "A",
        "AddressType": "Postal"
      },
      {
        "City": "B"
      },
      {
        "City": "C",
        "AddressType": "Street"
      }
    ]
  }
]

As you can see the first value in the AddressType enum is not coming through. I'd expect "City": "B" to have "AddressType": "Test" below it. I have played around with different numbers of enum values in different orders and each time the first value is never coming through.

Why is this and how can I fix it?

1

1 Answer 1

1

This was because I had JsConfig.ExcludeDefaultValues = true; in AppHosts.cs.

I could fix it by setting it to false or using a non default value for Test:

public enum AddressType
{
    Test = 1,
    Street,
    Postal        
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.