Represents a writer that provides a fast, non-cached, forward-only way of generating JSON data.
Inheritance: IDisposable
        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();
        }
Exemple #2
0
        /// <summary>
        /// Gets the remote interface values from the given <see cref="XElement"/> as a <see cref="JObject"/>.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="element"></param>
        public static void GetJson(JsonWriter writer, XElement element)
        {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(element != null);

            serializer.Serialize(writer, element);
        }
        /// <summary>
        /// Writes the json.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var serialize = true;

            if (_jsonSerializer.PreserveReferences)
            {
                var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName();
                using (var scopeManager = ScopeManager<ReferenceManager>.GetScopeManager(scopeName))
                {
                    var referenceManager = scopeManager.ScopeObject;

                    var referenceInfo = referenceManager.GetInfo(value);
                    if (referenceInfo != null && !referenceInfo.IsFirstUsage)
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName(Json.JsonSerializer.GraphRefId);
                        writer.WriteValue(referenceInfo.Id);
                        writer.WriteEndObject();

                        serialize = false;
                    }
                }
            }

            if (serialize)
            {
                _jsonSerializer.Serialize((ModelBase)value, writer);
            }
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if (value == null)
				writer.WriteValue("no");
			else 
				writer.WriteValue(((bool)value) ? "yes" : "no");
		}
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var list = (HalResource)value;

            list.Links.Add(new Link
            {
                Rel = "self",
                Href = list.Href
            });

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

            writer.WritePropertyName("_embedded");
            writer.WriteStartObject();
            writer.WritePropertyName(list.Rel);
            writer.WriteStartArray();
            foreach (HalResource halResource in (IEnumerable)value)
            {
                serializer.Serialize(writer, halResource);
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
            writer.WriteEndObject();
        }
        /// <summary>
        ///     Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var coordinateElements = value as List<IPosition>;
            if (coordinateElements != null && coordinateElements.Count > 0)
            {
                var coordinateArray = new JArray();

                foreach (var position in coordinateElements)
                {
                    // TODO: position types should expose a double[] coordinates property that can be used to write values 
                    var coordinates = (GeographicPosition)position;
                    var coordinateElement = new JArray(coordinates.Longitude, coordinates.Latitude);
                    if (coordinates.Altitude.HasValue)
                    {
                        coordinateElement = new JArray(coordinates.Longitude, coordinates.Latitude, coordinates.Altitude);
                    }

                    coordinateArray.Add(coordinateElement);
                }

                serializer.Serialize(writer, coordinateArray);
            }
            else
            {
                serializer.Serialize(writer, value);
            }
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var collection = (NameValueCollection)value;

            writer.WriteStartObject();

            foreach (var key in collection.AllKeys)
            {
                writer.WritePropertyName(key);

                var values = collection.GetValues(key);
                if (values == null)
                {
                    writer.WriteNull();
                    continue;
                }
                if (values.Length == 1)
                {
                    writer.WriteValue(values[0]);
                }
                else
                {
                    writer.WriteStartArray();

                    foreach (var item in values)
                    {
                        writer.WriteValue(item);
                    }

                    writer.WriteEndArray();
                }

            }
            writer.WriteEndObject();
        }
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     IFieldQuery fq = value as IFieldQuery;
     if (fq != null)
     {
         writer.WriteStartObject();
         writer.WritePropertyName(fq.Field);
         writer.WriteStartObject();
         if (fq is IValue)
         {
             IValue v = fq as IValue;
             writer.WritePropertyName("value");
             writer.WriteValue(v.Value);
         }
         if (fq.Boost != 1.0)
         {
             writer.WritePropertyName("boost");
             writer.WriteValue(fq.Boost);
         }
         writer.WriteEndObject();
         writer.WriteEndObject();
     }
     else
         writer.WriteNull();
 }
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value == null)
         writer.WriteNull();
     else
         writer.WriteRawValue(EpochTime.ConvertDateTimeToEpoch((DateTime)value).ToString());
 }
 /// <summary>
 /// Writes objects to JSON. Currently not implemented
 /// </summary>
 /// <param name="writer">JSON Writer Object</param>
 /// <param name="value">Value to be written</param>
 /// <param name="serializer">JSON Serializer </param>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (serializer != null)
     {
         serializer.Serialize(writer, value);
     }
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            FeatureCollectionResult fc = (FeatureCollectionResult)value;

            serializer.Converters.Add(new FeatureResultJsonConverter());
            serializer.Converters.Add(new StringEnumConverter());
            //serializer.Converters.Add(new GeometryConverter());

            writer.WriteStartObject();

            if (fc.Id != null){
                writer.WritePropertyName("id");
                writer.WriteValue(fc.Id);
            }

            if (fc.Properties != null) {
                writer.WritePropertyName("properties");
                serializer.Serialize(writer, (fc.Properties));
            }

            if (fc.FeatureResults != null) {
                writer.WritePropertyName("features");
                serializer.Serialize(writer, fc.FeatureResults.ToArray());
            }

            writer.WritePropertyName("type");
            serializer.Serialize(writer, (fc.Type));

            writer.WriteEndObject();
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var contract = serializer.ContractResolver as SettingsContractResolver;

			IDictionary dictionary = (IDictionary) value;
			writer.WriteStartObject();

			foreach (DictionaryEntry entry in dictionary)
			{
				if (entry.Value == null)
					continue;
				string key;
				var pp = entry.Key as PropertyPathMarker;
				var pn = entry.Key as PropertyNameMarker;
				var im = entry.Key as IndexNameMarker;
				if (contract == null)
					key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
				else if (pp != null)
					key = contract.Infer.PropertyPath(pp);
				else if (pn != null)
					key = contract.Infer.PropertyName(pn);
				else if (im != null)
					key = contract.Infer.IndexName(im);
				else
					key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
				writer.WritePropertyName(key);
				serializer.Serialize(writer, entry.Value);
			}

			writer.WriteEndObject();
		}
        public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
        {
            if(value == null)
            {
                writer.WriteNull();
                return;
            }

            var obj = value as EthSyncing;

            if(obj.IsSynching)
            {
                writer.WriteStartObject();

                writer.WritePropertyName(StartingBlockKey);
                serializer.Serialize(writer, obj.StartingBlock.Value);

                writer.WritePropertyName(CurrentBlockKey);
                serializer.Serialize(writer, obj.CurrentBlock.Value);

                writer.WritePropertyName(HighestBlockKey);
                serializer.Serialize(writer, obj.HighestBlock.Value);

                writer.WriteEndObject();
            }
            else
            {
                writer.WriteValue(false);
            }
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var push = value as PushNotification;
            if (push == null)
            {
                writer.WriteNull();
                return;
            }

            writer.StartObject();
            // Write push type
            if (string.IsNullOrWhiteSpace(push.Query) == false)
                writer.WriteProperty("query", push.Query);
            else if( push.Channels.Count() > 0 )
                writer.WriteArray("channels", push.Channels);
            else if( push.DeviceIds.Count() > 0 )
                writer.WriteArray("deviceids", push.DeviceIds);
            else
                writer.WriteProperty("broadcast", true);
            // Write data
            WriteData(writer, push);
            // Write platform options
            WritePlatformOptions(writer, push.PlatformOptions);
            writer.EndObject();

        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var request = value as IRegisterPercolatorRequest;

			if (request == null) return;

			writer.WriteStartObject();

			if (request.Query != null)
			{
				writer.WritePropertyName("query");
				serializer.Serialize(writer, request.Query);
			}

			if (request.Metadata != null)
			{
				foreach(var kv in request.Metadata)
				{
					writer.WritePropertyName(kv.Key);
					writer.WriteValue(kv.Value);
				}
			}

			writer.WriteEndObject();
		}
Exemple #16
0
        public void FormatJson(ref JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName("type");
            writer.WriteValue("table");

            writer.WritePropertyName("headers");
            writer.WriteStartArray();
            foreach(var header in this.headers.ToArray())
            {
                writer.WriteValue(header);
            }
            writer.WriteEndArray();

            writer.WritePropertyName("rows");
            writer.WriteStartArray();
            foreach (var row in this.rows.ToArray())
            {
                writer.WriteStartArray();

                foreach( var field in row)
                {
                    writer.WriteValue(field);
                }

                writer.WriteEndArray();
            }
            writer.WriteEndArray();

            writer.WriteEndObject();
        }
        /// <summary>
        ///     Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var coordinateElements = value as List<LineString>;
            if (coordinateElements != null && coordinateElements.Count > 0)
            {
                if (coordinateElements[0].Coordinates[0] != null)
                {
                    writer.WriteStartArray();

                    foreach (var subPolygon in coordinateElements)
                    {
                        LineStringConverter.WriteJson(writer, subPolygon.Coordinates, serializer);
                    }

                    writer.WriteEndArray();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                serializer.Serialize(writer, value);
            }
        }
Exemple #18
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var mode = (GameMode)value;
            string result;
            switch (mode)
            {
                case GameMode.Classic:
                    result = "CLASSIC";
                    break;
                case GameMode.Aram:
                    result = "ARAM";
                    break;
                case GameMode.Dominion:
                    result = "ODIN";
                    break;
                case GameMode.FirstBlood:
                    result = "FIRSTBLOOD";
                    break;
                case GameMode.OneForAll:
                    result = "ONEFORALL";
                    break;
                case GameMode.Tutorial:
                    result = "TUTORIAL";
                    break;

                //Fix for rengar
                case GameMode.Any:
                    result = "any";
                    break;
                default:
                    result = string.Empty;
                    break;
            }
            serializer.Serialize(writer, result);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var heartActivitiesIntraday = value as HeartActivitiesIntraday;

            //{
            writer.WriteStartObject();

            // "DatasetInterval" : "1"
            writer.WritePropertyName("DatasetInterval");
            writer.WriteValue(heartActivitiesIntraday.DatasetInterval);

            // "DatasetType" : "SecondsHeartrate"
            writer.WritePropertyName("DatasetType");
            writer.WriteValue(heartActivitiesIntraday.DatasetType);

            writer.WritePropertyName("Dataset");
            writer.WriteStartArray();
            foreach (var datasetInverval in heartActivitiesIntraday.Dataset)
            {
                // "Time" : "2008-09-22T14:01:54.9571247Z"
                writer.WritePropertyName("Time");
                writer.WriteValue(datasetInverval.Time.ToString("o"));

                // "Value": 1
                writer.WritePropertyName("Value");
                writer.WriteValue(datasetInverval.Value);

            }
            writer.WriteEndArray();
            
            //}
            writer.WriteEndObject();

        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                var id = (HiveId)value;
                
                writer.WriteStartObject();
                writer.WritePropertyName("htmlId");
                writer.WriteValue(id.GetHtmlId());

                writer.WritePropertyName("rawValue");
                writer.WriteValue(id.ToString());

                writer.WritePropertyName("value");
                writer.WriteValue(id.Value.Value == null ? "" : id.Value.Value.ToString());

                writer.WritePropertyName("valueType");
                writer.WriteValue(id.Value.Type);

                writer.WritePropertyName("provider");
                writer.WriteValue(id.ProviderId.IsNullOrWhiteSpace() ? "" : id.ProviderId);

                writer.WritePropertyName("scheme");
                writer.WriteValue(id.ProviderGroupRoot == null ? "" : id.ProviderGroupRoot.ToString());

                writer.WriteEndObject();                
            }

        }
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value != null)
         writer.WriteValue(value.ToString()); // adds quotes around the number
     else
         writer.WriteNull();
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var links = new HashSet<Link>((IList<Link>)value, new LinkEqualityComparer());

            writer.WriteStartObject();

            var lookup = links.ToLookup(l => l.Rel);

            foreach (var rel in lookup)
            {
                writer.WritePropertyName(rel.Key);
                if (rel.Count() > 1)
                    writer.WriteStartArray();
                foreach (var link in rel)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("href");
                    writer.WriteValue(ResolveUri(link.Href));

                    if (link.IsTemplated)
                    {
                        writer.WritePropertyName("templated");
                        writer.WriteValue(true);
                    }

                    writer.WriteEndObject();
                }
                if (rel.Count() > 1)
                    writer.WriteEndArray();
            }
            writer.WriteEndObject();
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var request = value as IMultiGetRequest;
			writer.WriteStartObject();
			if (!(request?.Documents.HasAny()).GetValueOrDefault(false))
			{
				writer.WriteEndObject();
				return;
			}
			var docs = request.Documents.Select(d =>
			{
				if (request.Index != null) d.Index = null;
				if (request.Type != null) d.Type = null;
				return d;
			}).ToList();

			var flatten = docs.All(p => p.CanBeFlattened);

			writer.WritePropertyName(flatten ? "ids" : "docs");
			writer.WriteStartArray();
			foreach (var id in docs)
			{
				if (flatten)
					serializer.Serialize(writer, id.Id);
				else
					serializer.Serialize(writer, id);
			}
			writer.WriteEndArray();
			writer.WriteEndObject();
		}
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                var notifications = (ClientNotifications)value;
                writer.WriteStartArray();

                foreach (var p in notifications)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("id");
                    writer.WriteValue(p.Id.ToString("N"));
                    writer.WritePropertyName("message");
                    writer.WriteValue(p.Message);
                    writer.WritePropertyName("title");
                    writer.WriteValue(p.Title);
                    writer.WritePropertyName("type");
                    writer.WriteValue(p.Type.ToString().ToLower());
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }

        }
        public void Write(JsonWriter writer)
        {
            Validate();

            writer.WriteStartObject();

            writer.WritePropertyName("proximityUUID");
            writer.WriteValue(ProximityUUID);

            if (!string.IsNullOrEmpty(RelevantText))
            {
                writer.WritePropertyName("relevantText");
                writer.WriteValue(RelevantText);
            }

            if (Minor.HasValue)
            {
                writer.WritePropertyName("minor");
                writer.WriteValue(Minor);
            }

            if (Major.HasValue)
            {
                writer.WritePropertyName("major");
                writer.WriteValue(Major);
            }

            writer.WriteEndObject();
        }
        public static void WriteTo(Bundle bundle, JsonWriter writer, bool summary = false)
        {
            if (bundle == null) throw new ArgumentException("Bundle cannot be null");

            JObject result = new JObject();

            result.Add(new JProperty(JsonDomFhirReader.RESOURCETYPE_MEMBER_NAME, "Bundle"));

            if (!String.IsNullOrWhiteSpace(bundle.Title))
                result.Add(new JProperty(BundleXmlParser.XATOM_TITLE, bundle.Title));
            if (SerializationUtil.UriHasValue(bundle.Id)) result.Add(new JProperty(BundleXmlParser.XATOM_ID, bundle.Id));
            if (bundle.LastUpdated != null) 
                result.Add(new JProperty(BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));

            if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
                result.Add(jsonCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
            if (bundle.TotalResults != null) result.Add(new JProperty(BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults.ToString()));
          
            if (bundle.Links.Count > 0)
                result.Add(new JProperty(BundleXmlParser.XATOM_LINK, jsonCreateLinkArray(bundle.Links)));
            if (bundle.Tags != null && bundle.Tags.Count() > 0)
                result.Add( TagListSerializer.CreateTagCategoryPropertyJson(bundle.Tags));

            var entryArray = new JArray();

            foreach (var entry in bundle.Entries)
                entryArray.Add(createEntry(entry,summary));

            result.Add(new JProperty(BundleXmlParser.XATOM_ENTRY, entryArray));

            result.WriteTo(writer);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Claim source = (Claim)value;

            var target = new ClaimLite(source);
            serializer.Serialize(writer, target);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var relations = (Relations)value;

            writer.WriteStartObject();

            var groupedByRel = relations.Links
                .GroupBy(_ => _.Rel)
                .ToDictionary(_ => _.Key, _ => _.ToArray());

            var allRelsExceptWellKnown = groupedByRel.Keys
                .Where(key => key != Link.CuriesRel && key != Link.SelfRel).ToList();

            // Not strictly required, but we will write the nodes in a nice order.
            if (groupedByRel.ContainsKey(Link.SelfRel))
            {
                WriteLinks(writer, serializer, Link.SelfRel, links: groupedByRel[Link.SelfRel]);
            }

            if (groupedByRel.ContainsKey(Link.CuriesRel))
            {
                WriteLinks(writer, serializer, Link.CuriesRel, links: groupedByRel[Link.CuriesRel]);
            }

            foreach (var rel in allRelsExceptWellKnown)
            {
                WriteLinks(writer, serializer, rel, links: groupedByRel[rel]);
            }

            writer.WriteEndObject();
        }        
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var s = new StringWriter();
     var w = new JsonTextWriter(s);
     base.WriteJson(w, value, serializer);
     writer.WriteValue(s.ToString().ToLower().Trim('"'));
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            JArray array = new JArray();
            IList list = (IList)value;
            if (list.Count > 0)
            {
                JArray keys = new JArray();

                JObject first = JObject.FromObject(list[0], serializer);
                foreach (JProperty prop in first.Properties())
                {
                    keys.Add(new JValue(prop.Name));
                }
                array.Add(keys);

                foreach (object item in list)
                {
                    JObject obj = JObject.FromObject(item, serializer);
                    JArray itemValues = new JArray();
                    foreach (JProperty prop in obj.Properties())
                    {
                        itemValues.Add(prop.Value);
                    }
                    array.Add(itemValues);
                }
            }
            array.WriteTo(writer);
        }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null && value is Renderer)
            {
                string temp = ((Renderer)value).ToConfigString();

                if (temp.IsNotEmpty())
                {
                    writer.WriteRawValue(temp);
                    return;
                }
            }
            writer.WriteRawValue("null");
        }
Exemple #32
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value is string)
            {
                string temp = (string)value;

                if (temp.IsNotEmpty())
                {
                    writer.WriteValue(DateTimeUtils.ConvertNetToPHP(temp));
                    return;
                }
            }
            writer.WriteRawValue(null);
        }
Exemple #33
0
 public override void WriteJson(
     Newtonsoft.Json.JsonWriter writer,
     object value,
     JsonSerializer serializer)
 {
     if (value is DirectoryInfo directory)
     {
         writer.WriteValue(directory.FullName);
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(value));
     }
 }
 static int CreateWriter(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Newtonsoft.Json.Linq.JContainer obj = (Newtonsoft.Json.Linq.JContainer)ToLua.CheckObject <Newtonsoft.Json.Linq.JContainer>(L, 1);
         Newtonsoft.Json.JsonWriter      o   = obj.CreateWriter();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            JToken t = JToken.FromObject(value);

            if (t.Type != JTokenType.Object)
            {
                Decimal d = (Decimal)t;
                writer.WriteValue(d);
            }
            else
            {
                JObject o = (JObject)t;
                o.WriteTo(writer);
            }
        }
Exemple #36
0
            public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
            {
                var oDataValue = value as ODataValue;

                if (oDataValue != null)
                {
                    // for ODataValue, we just serialize the inner value
                    serializer.Serialize(writer, oDataValue.Value);
                }
                else
                {
                    // ODataEntity just serializes as a dictionary
                    serializer.Serialize(writer, ((ODataEntity)value).Values);
                }
            }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            Control control = value as Control;

            if (control != null)
            {
                if (!control.Visible)
                {
                    writer.WriteNull();
                    return;
                }

                writer.WriteRawValue(this.Format(control));
            }
        }
Exemple #38
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var oneOfValue = ((IOneOf)value).Value;

            if (oneOfValue == null)
            {
                throw new JsonSerializationException($"Failed to serialize path '{writer.Path}' because the {value.GetType().Name}'.{nameof(IOneOf.Value)} has unsupported null value.");
            }

            serializer.Serialize(writer, new OneOfContainer
            {
                Value = oneOfValue,
                Type  = oneOfValue.GetType().AssemblyQualifiedName
            });
        }
Exemple #39
0
            public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
            {
                int seconds;

                if (value is DateTime time)
                {
                    seconds = DateTimeToEpoch(time);
                }
                else
                {
                    throw new Exception("Expected date object value.");
                }

                writer.WriteValue(seconds);
            }
        public override void WriteJson(
            Newtonsoft.Json.JsonWriter writer,
            object value,
            JsonSerializer serializer)
        {
            switch (value)
            {
            case RepresentedType representedType:
                writer.WriteValue(representedType.Name);
                break;

            default:
                throw new NotImplementedException();
            }
        }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            switch ((ThreeStateBool)value)
            {
            case ThreeStateBool.False:
                writer.WriteRawValue("false");
                return;

            case ThreeStateBool.True:
                writer.WriteRawValue("true");
                return;
            }

            writer.WriteRawValue("undefined");
        }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            DynamicConfigDictionary config = (DynamicConfigDictionary)value;

            if (config != null)
            {
                var keys = config.GetDynamicMemberNames();

                foreach (string key in keys)
                {
                    writer.WritePropertyName(Ext.Net.Utilities.StringUtils.ToLowerCamelCase(key));
                    writer.WriteRawValue(JSON.Serialize(config.GetDynamicValue(key), new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()));
                }
            }
        }
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        if (value.GetType() != typeof(Dictionary <NoteType, T>))
        {
            throw new InvalidCastException();
        }
        var dictionary = (Dictionary <NoteType, T>)value;
        var jObject    = new JObject();

        foreach (var type in (NoteType[])Enum.GetValues(typeof(NoteType)))
        {
            jObject[((int)type).ToString()] = JsonConvert.SerializeObject(dictionary[type]);
        }

        jObject.WriteTo(writer);
    }
Exemple #44
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            string[] arr = value as string[];

            if (arr != null)
            {
                if (arr.Length == 1)
                {
                    writer.WriteRawValue("\"" + arr[0] + "\"");
                }
                else
                {
                    writer.WriteRawValue("[{0}]".FormatWith(((string[])value).Join(",", "\"{0}\"")));
                }
            }
        }
Exemple #45
0
 static int WriteTo(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         Newtonsoft.Json.Linq.JArray     obj  = (Newtonsoft.Json.Linq.JArray)ToLua.CheckObject <Newtonsoft.Json.Linq.JArray>(L, 1);
         Newtonsoft.Json.JsonWriter      arg0 = (Newtonsoft.Json.JsonWriter)ToLua.CheckObject <Newtonsoft.Json.JsonWriter>(L, 2);
         Newtonsoft.Json.JsonConverter[] arg1 = ToLua.CheckObjectArray <Newtonsoft.Json.JsonConverter>(L, 3);
         obj.WriteTo(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("name");
     writer.WriteValue(this.Name);
     writer.WritePropertyName("prop");
     writer.WriteValue(this.Prop);
     writer.WritePropertyName("rotation");
     writer.WriteStartArray();
     foreach (Rotation r in this.Rotations)
     {
         r.WriteToJson(writer);
     }
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
Exemple #47
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value is Unit)
            {
                Unit unit = (Unit)value;

                if (unit.Type == UnitType.Pixel)
                {
                    writer.WriteValue(Convert.ToInt32(((Unit)value).Value));
                }
                else if (unit.Type == UnitType.Percentage)
                {
                    writer.WriteValue(unit.Value.ToString() + "%");
                }
            }
        }
Exemple #48
0
 static int WriteTo(IntPtr L)
 {
     try
     {
         int count = LuaDLL.lua_gettop(L);
         Newtonsoft.Json.Linq.JValue     obj  = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject(L, 1, typeof(Newtonsoft.Json.Linq.JValue));
         Newtonsoft.Json.JsonWriter      arg0 = (Newtonsoft.Json.JsonWriter)ToLua.CheckObject(L, 2, typeof(Newtonsoft.Json.JsonWriter));
         Newtonsoft.Json.JsonConverter[] arg1 = ToLua.CheckParamsObject <Newtonsoft.Json.JsonConverter>(L, 3, count - 2);
         obj.WriteTo(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #49
0
        public override void ValueToJson(Newtonsoft.Json.JsonWriter writer, Row row, JsonSerializer serializer)
        {
            var value = _getValue(row);

            if (value == null)
            {
                writer.WriteNull();
            }
            else //if (EnumType == null) şimdilik enum tipi belirtilse de string e çevrilerek yazma işlemi iptal, flag ile daha sonra ekleyelim
            {
                writer.WriteValue(value.Value);
            }
            //else if (EnumType.IsEnum)
            //    writer.WriteValue(Enum.GetName(EnumType, value.Value));
            //else if (EnumType.IsSubclassOf(typeof(DataEnum)))
            //    writer.WriteValue(DataEnum.ConvertFromInt32(EnumType, value.Value).Key);
        }
Exemple #50
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value)
        {
            if (value is DateTime)
            {
                DateTime date = (DateTime)value;
                if (date != DateTime.MinValue)
                {
                    writer.WriteValue(date.ToString(DateTimeFormat, CultureInfo.InvariantCulture));
                }
                else
                {
                    writer.WriteRawValue("null");
                }
                return;
            }

            writer.WriteRawValue("null");
        }
        public override void WriteJson(
            Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            var cursor   = (List <BsonDocument>)value;
            var settings = new JsonWriterSettings
            {
                OutputMode = JsonOutputMode.Strict
            };

            writer.WriteStartArray();

            foreach (BsonDocument document in cursor)
            {
                writer.WriteRawValue(document.ToJson(settings));
            }

            writer.WriteEndArray();
        }
Exemple #52
0
            /// <summary>
            /// Serialise the timeline event to JSON
            /// </summary>
            public void Serialise(Newtonsoft.Json.JsonWriter writer, Newtonsoft.Json.JsonSerializer serializer)
            {
                Debug.Assert(_item is not null);
                JArray meta = new JArray
                {
                    TimelineEventType,
                    ID,
                    Parent
                };

                meta.WriteTo(writer);

                if (TimelineEventType == eTimelineEvent.APICall)
                {
                    APICALL apic = (Logging.APICALL)_item;
                    apic.Serialise(writer, serializer);
                }
            }
Exemple #53
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
        {
            try
            {
                _isWriting = true;

                var jObject = Newtonsoft.Json.Linq.JObject.FromObject(value, serializer);

                // HACK
                //jObject.AddFirst(new Newtonsoft.Json.Linq.JProperty(_discriminator, value.GetType().Name));

                writer.WriteToken(jObject.CreateReader());
            }
            finally
            {
                _isWriting = false;
            }
        }
Exemple #54
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            LoadMask mask = value as LoadMask;

            if (mask != null && mask.ShowMask)
            {
                string jsonMask = new ClientConfig().Serialize(mask);

                if (jsonMask.IsEmpty() || jsonMask.Equals("{}"))
                {
                    writer.WriteValue(true);
                }
                else
                {
                    writer.WriteRawValue(jsonMask);
                }
            }
        }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value is string)
            {
                string re = (string)value;

                if (!re.StartsWith("/", StringComparison.InvariantCulture))
                {
                    re = "/{0}".FormatWith(re);
                }

                if (!re.EndsWith("/", StringComparison.InvariantCulture))
                {
                    re = "{0}/".FormatWith(re);
                }

                writer.WriteRawValue(re);
            }
        }
Exemple #56
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            // See also reference example at https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm
            JToken t = JToken.FromObject(value);

            if (t is JObject)
            {
                JObject o             = (JObject)t;
                var     missingFields = (value as HandleAdditionalJsonFields).AdditionalJsonFields;
                if (!missingFields.IsNullOrEmpty())
                {
                    foreach (var f in missingFields)
                    {
                        o.Add(new JProperty(f.Key, f.Value));
                    }
                }
            }
            t.WriteTo(writer);
        }
        public override void WriteJson(Newton.JsonWriter writer, object value, Newton.JsonSerializer serializer)
        {
            var result = value as IResult;

            writer.WriteStartObject();

            writer.WritePropertyName("succeed");
            serializer.Serialize(writer, result.Succeed);

            writer.WritePropertyName("data");
            serializer.Serialize(writer, result.Data);

            if (!string.IsNullOrEmpty(result.Message))
            {
                writer.WritePropertyName("msg");
                serializer.Serialize(writer, result.Message);
            }

            writer.WriteEndObject();
        }
Exemple #58
0
            /// <summary>
            /// Serialise an API event to JSON
            /// </summary>
            /// <returns>JObject of the event</returns>
            public void Serialise(Newtonsoft.Json.JsonWriter writer, Newtonsoft.Json.JsonSerializer serializer)
            {
                writer.WriteStartArray();

                writer.WriteValue(Graph !.ConstructedTime);
                writer.WriteValue(Node !.Index);
                writer.WriteValue(Index);
                writer.WriteValue(Repeats);
                writer.WriteValue(UniqID);

                if (APIDetails.HasValue)
                {
                    serializer.Serialize(writer, APIDetails);
                }
                else
                {
                    writer.WriteNull();
                }
                writer.WriteEndArray();
            }
 /// <summary>
 /// Invoked when data has to be serialized before sending to the caller.
 /// This method will fail if the service code tries to send DateTime
 //  instead of DateTimeOffset.
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="value"></param>
 /// <param name="serializer"></param>
 public override void WriteJson(Newtonsoft.Json.JsonWriter writer,
                                object value,
                                Newtonsoft.Json.JsonSerializer serializer)
 {
     // IF YOU WANT TO DEAL WITH DATETIME
     // THIS SHOWS HOW TO DO THAT
     if (value is DateTime)
     {
         DateTime utcTime = (DateTime)value;
         writer.WriteRawValue(String.Format("\"{0}\"",
                                            ((DateTime)utcTime).ToString(this.DateTimeFormat)));
     }
     // EXAMPLE OF DateTimeOffset formatting
     else if (value is DateTimeOffset)
     {
         DateTimeOffset offs = (DateTimeOffset)value;
         writer.WriteRawValue(String.Format("\"{0} UTC({1:##})\"",
                                            offs.ToString(this.DateTimeFormat), offs.Offset.Minutes));
     }
 }
        public override void WriteJson(
            Newtonsoft.Json.JsonWriter writer,
            object value,
            JsonSerializer serializer)
        {
            switch (value)
            {
            case JsonPayload json:
                writer.WriteRawValue(json);
                break;

            case ISerializableObject _:
                writer.WriteRawValue(Representations.RepresentationManager.ToJson(value));
                break;

            case null:
                writer.WriteNull();
                break;
            }
        }