visoft/ruby_odata

Primitive values of type 'Edm.Decimal' and 'Edm.Int64' must be quoted in the payload. Make sure the value is quoted.

tomaswitek opened this issue · 4 comments

Hi,
I am trying to create entity, but I am getting exceptions about Edm.Decimal.
I think the problem is the Price attribute.
I have tried almost everything:

self.Price = BigDecimal(500)
self.Price = 500
self.Price = "500"
module Idoklad
  class IssuedInvoiceItem < Entity

    attr_accessor :InvoiceId, :Name, :Amount, :Unit, :Price, :PriceType, :VatRateType

    def initialize(item)
      self.Price = BigDecimal(500)
      self.Name = "HP tiskarna"
      self.Amount = 5
      self.PriceType = 1
      self.Unit = "Kus"
      self.VatRateType = 1
    end
  end
end

I am still getting this error:

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code/>
  <m:message xml:lang="en-US">An error occurred while processing this request.</m:message>
  <m:innererror>
    <m:message>Cannot convert a primitive value to the expected type 'Edm.Decimal'. See the inner exception for more details.</m:message>
    <m:type>Microsoft.Data.OData.ODataException</m:type>
    <m:stacktrace>   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, Boolean validateNullValue)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadPrimitiveValue(Boolean insideJsonObjectValue, IEdmPrimitiveTypeReference expectedValueTypeReference, Boolean validateNullValue)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightEntryAndFeedDeserializer.ReadEntryDataProperty(IODataJsonLightReaderEntryState entryState, IEdmProperty edmProperty, String propertyTypeName)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightEntryAndFeedDeserializer.ReadEntryPropertyWithValue(IODataJsonLightReaderEntryState entryState, String propertyName)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightEntryAndFeedDeserializer.&lt;&gt;c__DisplayClass2.&lt;ReadEntryContent&gt;b__0(PropertyParsingResult propertyParsingResult, String propertyName)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightEntryAndFeedDeserializer.ReadEntryContent(IODataJsonLightReaderEntryState entryState)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReader.ReadAtEntryStartImplementationSynchronously()&#13;
   at Microsoft.Data.OData.ODataReaderCore.ReadImplementation()&#13;
   at Microsoft.Data.OData.ODataReaderCore.InterceptException[T](Func`1 action)&#13;
   at System.Data.Services.Serializers.EntityDeserializer.ReadEntry(ODataReader odataReader, SegmentInfo topLevelSegmentInfo)&#13;
   at System.Data.Services.Serializers.EntityDeserializer.Read(SegmentInfo segmentInfo)&#13;
   at System.Data.Services.Serializers.ODataMessageReaderDeserializer.Deserialize(SegmentInfo segmentInfo)</m:stacktrace>
    <m:internalexception>
      <m:message>Primitive values of type 'Edm.Decimal' and 'Edm.Int64' must be quoted in the payload. Make sure the value is quoted.</m:message>
      <m:type>Microsoft.Data.OData.ODataException</m:type>
      <m:stacktrace>   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertInt32Value(Int32 intValue, Type targetType, IEdmPrimitiveTypeReference primitiveTypeReference)&#13;
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, Boolean validateNullValue)</m:stacktrace>
    </m:internalexception>
  </m:innererror>
</m:error>

Any ideas?
Thx

Here you can find service metadata:
https://app.idoklad.cz/odataservice.svc/$metadata
Thx

Did you try self.Price = "500.00"

I found the problem:

self.Price = "500"
self.Amount = "5"

These variables have to be quoted.
Thx

+1 for REST API