4

I found one strange issue in postman. In below request amount is integer field.

{ "merchantId": 49, "amount": 020 }

When I pass Amount 020 instead of 20. In API controller I received amount 16. When I pass 0100 I receive 64.

If I pass in double quotes like "020" or "0100". Then I get 20 and 100.

Below is controller method and request class:

    [HttpPost]
    public IHttpActionResult Post(XXXXXXXXCommand command)
    {
        IHttpActionResult result = null;

        using (_logger.PushWeb())
        {
            _logger.Info("POST request to /transactions/debits/accountsetup", command);
            try
            {

            }

            catch (MerchantNotFoundException ex)
            {
                _logger.Error("XXXX", ex);


            }

        }
        return result;
    }


[DataContract(Name = "XXXXCommand")]
public class XXXXXXCommand : CommandBase
{
    /// <summary>
    /// Merchant ID 
    /// </summary>
    [DataMember(Name = "merchantId", Order = 1)]
    public int MerchantId { get; set; }

    /// <summary>
    /// Transaction amount
    /// </summary>
    [DataMember(Name = "amount", Order = 2)]
    public int Amount { get; set; }
}

It looks like postman bug.

Deepak Kumar
  • 648
  • 6
  • 14

2 Answers2

5

Prefixing a number with 0 makes it interpreted as an octal number.

Octal number syntax uses a leading zero. If the digits after the 0 are outside the range 0 through 7, the number will be interpreted as a decimal number.

var n = 0755; // 493
var m = 0644; // 420

For more information see this link.

Rakesh Kumar
  • 2,701
  • 9
  • 38
  • 66
1

This answer indicates that a leading zero defines an octal number - or base 8 - in JavaScript. So the serializer is interpreting what you're passing it correctly according to the standard.

Leading zeroes have no meaning to decimal integers, so if you need the zero to be maintained - I can't see how you could, if your model has integer properties - then make it a string. But there is no incorrect behaviour here.

Tom W
  • 5,108
  • 4
  • 30
  • 52