Newtonsoft.Json.JsonSerializer.Serialize C# (CSharp) Method

Serialize() public method

Serializes the specified Object and writes the Json structure to a Stream using the specified JsonWriter.
public Serialize ( JsonWriter jsonWriter, object value ) : void
jsonWriter JsonWriter The used to write the Json structure.
value object The to serialize.
return void
    public void Serialize(JsonWriter jsonWriter, object value)
    {
      SerializeInternal(jsonWriter, value);
    }

Same methods

JsonSerializer::Serialize ( TextWriter textWriter, object value ) : void

Usage Example

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var representation = value as Representation;
            if (representation != null)
                representation.RepopulateHyperMedia();

            var list = (IRepresentationList)value;

            writer.WriteStartObject();
            writer.WritePropertyName("_links");
            serializer.Serialize(writer, list.Links);

            writer.WritePropertyName("_embedded");
            writer.WriteStartObject();
            writer.WritePropertyName(list.Rel);
            writer.WriteStartArray();
            foreach (Representation halResource in list)
            {
                serializer.Serialize(writer, halResource);
            }

            writer.WriteEndArray();
            writer.WriteEndObject();

            var listType = list.GetType();
            var propertyInfos = typeof(RepresentationList<>).GetProperties().Select(p => p.Name);
            foreach (var property in listType.GetProperties().Where(p => !propertyInfos.Contains(p.Name)))
            {
                writer.WritePropertyName(property.Name.ToLower());
                serializer.Serialize(writer, property.GetValue(value, null));
            }

            writer.WriteEndObject();
        }
All Usage Examples Of Newtonsoft.Json.JsonSerializer::Serialize