/// <summary>
        /// Writes the entity result to the response message.
        /// </summary>
        /// <param name="graph">The entity result to write.</param>
        /// <param name="type">The type of the entity.</param>
        /// <param name="messageWriter">The message writer.</param>
        /// <param name="writeContext">The writing context.</param>
        public override void WriteObject(
            object graph,
            Type type,
            ODataMessageWriter messageWriter,
            ODataSerializerContext writeContext)
        {
            RawResult rawResult = graph as RawResult;

            if (rawResult != null)
            {
                graph = rawResult.Result;
                type  = rawResult.Type;
            }

            if (writeContext != null)
            {
                graph = RestierPrimitiveSerializer.ConvertToPayloadValue(graph, writeContext);
            }

            if (graph == null)
            {
                // This is to make ODataRawValueSerializer happily serialize null value.
                graph = string.Empty;
            }

            base.WriteObject(graph, type, messageWriter, writeContext);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultRestierSerializerProvider" /> class.
 /// </summary>
 /// <param name="rootContainer">The container to get the service</param>
 public DefaultRestierSerializerProvider(IServiceProvider rootContainer) : base(rootContainer)
 {
     this.resourceSetSerializer = new RestierResourceSetSerializer(this);
     this.primitiveSerializer   = new RestierPrimitiveSerializer();
     this.rawSerializer         = new RestierRawSerializer();
     this.resourceSerializer    = new RestierResourceSerializer(this);
     this.collectionSerializer  = new RestierCollectionSerializer(this);
     this.enumSerializer        = new RestierEnumSerializer(this);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultRestierSerializerProvider" /> class.
        /// </summary>
        /// <param name="rootContainer">The container to get the service</param>
        /// <param name="payloadValueConverter">The OData payload value converter to use.</param>
        public DefaultRestierSerializerProvider(IServiceProvider rootContainer, ODataPayloadValueConverter payloadValueConverter) : base(rootContainer)
        {
            Ensure.NotNull(rootContainer, nameof(rootContainer));
            Ensure.NotNull(payloadValueConverter, nameof(payloadValueConverter));

            this.resourceSetSerializer = new RestierResourceSetSerializer(this);
            this.primitiveSerializer   = new RestierPrimitiveSerializer(payloadValueConverter);
            this.rawSerializer         = new RestierRawSerializer(payloadValueConverter);
            this.resourceSerializer    = new RestierResourceSerializer(this);
            this.collectionSerializer  = new RestierCollectionSerializer(this);
            this.enumSerializer        = new RestierEnumSerializer(this);
        }