1

I have a custom ODataResourceSerializer which under some conditions adds new properties to a resource, that works perfectly.

I am trying to add a new simple int[] property

the resource is a dynamic resource that is registered at runtime and does not have these properties on the model.

this code

case TypeX tx:

  propertiesToReturn.Add(new ODataProperty()
     {
        Name = "TypeX",
        Value = new ODataCollectionValue()
        {
           Items = new int[] {1,2,3}
        }
     });

gives me whrn the resource is sent to the ODataJsonLightPropertySerializer.WriteCollectionProperty

A type named 'System.Int32[]' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.

and when trying to add the value directly to the odata property

new ODataProperty()
{
    Value = new int[] { 1, 2, 3 }   
}

I get on add

An ODataPrimitiveValue was instantiated with a value of type 'System.Int32[]'. ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types

I tried adding int[] to the model builder I tried adding a type to the ODataCollectionValue

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mottibec
  • 146
  • 1
  • 6

1 Answers1

2

solved using ODataUntypedValue and serializing the value according to the return type "XML/JSON"

for example

Value = new ODataUntypedValue
{                            
    RawValue = JsonConvert.SerializeObject(new int[] { 1, 2, 3 })
}
mottibec
  • 146
  • 1
  • 6