예제 #1
0
        /// <summary>
        /// Finish writing an entry.
        /// </summary>
        /// <param name="entry">The entry to write.</param>
        protected override void EndEntry(ODataEntry entry)
        {
            if (entry == null)
            {
                Debug.Assert(
                    this.ParentNavigationLink != null && this.ParentNavigationLink.IsCollection.HasValue && !this.ParentNavigationLink.IsCollection.Value,
                    "when entry == null, it has to be and expanded single entry navigation");

                // this is a null expanded single entry and it is null, JSON null should be written as value in StartEntry()
                return;
            }

            // Get the projected properties
            JsonLightEntryScope entryScope = this.CurrentEntryScope;

            this.jsonLightEntryAndFeedSerializer.WriteEntryMetadataProperties(entryScope);

            // Write custom instance annotations
            this.jsonLightEntryAndFeedSerializer.InstanceAnnotationWriter.WriteInstanceAnnotations(entry.InstanceAnnotations, entryScope.InstanceAnnotationWriteTracker);

            this.jsonLightEntryAndFeedSerializer.WriteEntryEndMetadataProperties(entryScope, entryScope.DuplicatePropertyNamesChecker);

            // Close the object scope
            this.jsonWriter.EndObjectScope();
        }
예제 #2
0
        /// <summary>
        /// Start writing an entry.
        /// </summary>
        /// <param name="entry">The entry to write.</param>
        protected override void StartEntry(ODataEntry entry)
        {
            ODataNavigationLink parentNavLink = this.ParentNavigationLink;

            if (parentNavLink != null)
            {
                // Write the property name of an expanded navigation property to start the value.
                this.jsonWriter.WriteName(parentNavLink.Name);
            }

            if (entry == null)
            {
                Debug.Assert(
                    parentNavLink != null && !parentNavLink.IsCollection.Value,
                    "when entry == null, it has to be and expanded single entry navigation");

                // this is a null expanded single entry and it is null, so write a JSON null as value.
                this.jsonWriter.WriteValue((string)null);
                return;
            }

            // Write just the object start, nothing else, since we might not have complete information yet
            this.jsonWriter.StartObjectScope();

            JsonLightEntryScope entryScope = this.CurrentEntryScope;

            if (this.IsTopLevel)
            {
                // Write odata.context
                this.jsonLightEntryAndFeedSerializer.WriteEntryContextUri(entryScope.GetOrCreateTypeContext(this.jsonLightOutputContext.Model, this.jsonLightOutputContext.WritingResponse));
            }

            // Write the metadata
            this.jsonLightEntryAndFeedSerializer.WriteEntryStartMetadataProperties(entryScope);
            this.jsonLightEntryAndFeedSerializer.WriteEntryMetadataProperties(entryScope);

            // Write custom instance annotations
            this.jsonLightEntryAndFeedSerializer.InstanceAnnotationWriter.WriteInstanceAnnotations(entry.InstanceAnnotations, entryScope.InstanceAnnotationWriteTracker);

            // Write the properties
            ProjectedPropertiesAnnotation projectedProperties = GetProjectedPropertiesAnnotation(entryScope);

            this.jsonLightEntryAndFeedSerializer.JsonLightValueSerializer.AssertRecursionDepthIsZero();
            this.jsonLightEntryAndFeedSerializer.WriteProperties(
                this.EntryEntityType,
                entry.Properties,
                false /* isComplexValue */,
                this.DuplicatePropertyNamesChecker,
                projectedProperties);
            this.jsonLightEntryAndFeedSerializer.JsonLightValueSerializer.AssertRecursionDepthIsZero();

            // COMPAT 48: Position of navigation properties/links in JSON differs.
        }
예제 #3
0
        /// <summary>
        /// Start writing an entry.
        /// </summary>
        /// <param name="entry">The entry to write.</param>
        protected override void StartEntry(ODataEntry entry)
        {
            ODataNavigationLink parentNavLink = this.ParentNavigationLink;

            if (parentNavLink != null)
            {
                // Write the property name of an expanded navigation property to start the value.
                this.jsonLightOutputContext.JsonWriter.WriteName(parentNavLink.Name);
            }

            if (entry == null)
            {
                Debug.Assert(
                    parentNavLink != null && !parentNavLink.IsCollection.Value,
                    "when entry == null, it has to be and expanded single entry navigation");

                // this is a null expanded single entry and it is null, so write a JSON null as value.
                this.jsonLightOutputContext.JsonWriter.WriteValue(null);
                return;
            }

            // Write just the object start, nothing else, since we might not have complete information yet
            this.jsonLightOutputContext.JsonWriter.StartObjectScope();

            JsonLightEntryScope entryScope = this.CurrentEntryScope;

            if (this.IsTopLevel)
            {
                // Write odata.metadata
                this.jsonLightEntryAndFeedSerializer.TryWriteEntryMetadataUri(entryScope.GetOrCreateTypeContext(this.jsonLightOutputContext.Model, this.jsonLightOutputContext.WritingResponse));
            }

            // Write the annotation group in responses (if any)
            this.jsonLightEntryAndFeedSerializer.WriteAnnotationGroup(entry);

            // Write the metadata
            this.jsonLightEntryAndFeedSerializer.WriteEntryStartMetadataProperties(entryScope);
            this.jsonLightEntryAndFeedSerializer.WriteEntryMetadataProperties(entryScope);

            // Write custom instance annotations
            this.jsonLightEntryAndFeedSerializer.InstanceAnnotationWriter.WriteInstanceAnnotations(entry.InstanceAnnotations, entryScope.InstanceAnnotationWriteTracker);
        }