Paolo ponzano - 40 - Nov 4, 2014

Hello Demis, I’ve got a problem … I’ve the following class

 [DataContract]
    public class UpdatePositionsRequest : IReturnVoid
    {
        [DataMember]
        public List<Position> Positions { get; set; }
    }

    [DataContract]
    public class Position
    {
        [DataMember]
        public decimal? Quantity { get; set; }
        [DataMember]
        public decimal? Price { get; set; }
        [DataMember]
        public decimal? Accrual { get; set; }
        [DataMember]
        public decimal? ExchangeRate { get; set; }
        [DataMember]
        public decimal? CarryingPrice { get; set; }
        [DataMember]
        public decimal? CarryingExchangeRate { get; set; }
    }

but when I receive the following request

{
    “carryingExchangeRate” : 1,
    “carryingPrice” : 0E-7,
    “exchangeRate” : 1,
    “quantity” : 4039.346000,
    “price” : 0E-7,
  }

I got null value con carryingPrice and price … how can I threath them?

Thanks

I suspect the problem is either the JSON doesn’t match what the Service expects which based on the DTO should be something like:
{“Positions”:[{“carryingPrice”:1,…}]}

Or the values you’re trying to send aren’t valid decimals.

paolo ponzano:

Actually the only part of the object that is not correctly deserialized is the " 0E-7".
Sorry if the example i provided i missed to include the square parentheses.

Probably this format is not supported by ServiceStack deserializer but it’s part of the JSON standard so far.
http://www.json.org/

Is there a chance that it’s going to be supported?

paolo ponzano:

Demis if I use double it works…what’s wrong?

double holds a much larger range of floating point numbers than decimal.

paolo ponzano:

Ok built it also won’t work with 1e-2

the built-in double.Parse/decimal.Parse is what does the parsing, if it doesn’t work it’s not supported by that data type.