public void WriteJson(object value, IValueWriter writer) { if (value is null) { writer.Null(); } else { writer.Long(((UnixMillisecondTime)value).Value); } }
private static void SerializeObjectToJWriter(object instance, IValueWriter writer, IJsonStreamConverter converter) { if (converter is null) { throw new NullReferenceException(nameof(converter)); } if (instance is null) { writer.Null(); } else { converter.WriteJson(instance, writer); } }
public static void WriteJsonValue(LdValue value, IValueWriter writer) { switch (value.Type) { case LdValueType.Null: writer.Null(); break; case LdValueType.Bool: writer.Bool(value.AsBool); break; case LdValueType.Number: var asInt = value.AsInt; var asDouble = value.AsDouble; if ((double)asInt == asDouble) { writer.Int(asInt); } else { writer.Double(asDouble); } break; case LdValueType.String: writer.String(value.AsString); break; case LdValueType.Array: var arr = writer.Array(); foreach (var v in value.List) { WriteJsonValue(v, arr); } arr.End(); break; case LdValueType.Object: var obj = writer.Object(); foreach (var kv in value.Dictionary) { WriteJsonValue(kv.Value, obj.Name(kv.Key)); } obj.End(); break; } }
public void WriteJson(object value, IValueWriter writer) { var user = (User)value; if (user is null) { writer.Null(); return; } var obj = writer.Object(); obj.Name("key").String(user.Key); obj.MaybeName("secondary", user.Secondary != null).String(user.Secondary); obj.MaybeName("ip", user.IPAddress != null).String(user.IPAddress); obj.MaybeName("country", user.Country != null).String(user.Country); obj.MaybeName("firstName", user.FirstName != null).String(user.FirstName); obj.MaybeName("lastName", user.LastName != null).String(user.LastName); obj.MaybeName("name", user.Name != null).String(user.Name); obj.MaybeName("avatar", user.Avatar != null).String(user.Avatar); obj.MaybeName("email", user.Email != null).String(user.Email); if (user.AnonymousOptional.HasValue) { obj.Name("anonymous").Bool(user.Anonymous); } if (user.Custom.Count > 0) { var customObj = obj.Name("custom").Object(); foreach (var kv in user.Custom) { LdValueConverter.WriteJsonValue(kv.Value, customObj.Name(kv.Key)); } customObj.End(); } if (user.PrivateAttributeNames.Count > 0) { var attrsArr = obj.Name("privateAttributeNames").Array(); foreach (var n in user.PrivateAttributeNames) { attrsArr.String(n); } attrsArr.End(); } obj.End(); }
public void WriteJson(object value, IValueWriter writer) { var state = value as FeatureFlagsState; if (state is null) { writer.Null(); return; } var obj = writer.Object(); foreach (var entry in state._flags) { LdValueConverter.WriteJsonValue(entry.Value.Value, obj.Name(entry.Key)); } obj.Name("$valid").Bool(state._valid); var allMetadataObj = obj.Name("$flagsState").Object(); foreach (var entry in state._flags) { var flagMetadataObj = allMetadataObj.Name(entry.Key).Object(); var meta = entry.Value; flagMetadataObj.Name("variation").IntOrNull(meta.Variation); flagMetadataObj.Name("version").IntOrNull(meta.Version); flagMetadataObj.MaybeName("trackEvents", meta.TrackEvents).Bool(meta.TrackEvents); flagMetadataObj.MaybeName("debugEventsUntilDate", meta.DebugEventsUntilDate.HasValue) .Long(meta.DebugEventsUntilDate?.Value ?? 0); if (meta.Reason.HasValue) { EvaluationReasonConverter.WriteJsonValue(meta.Reason.Value, flagMetadataObj.Name("reason")); } flagMetadataObj.End(); } allMetadataObj.End(); obj.End(); }
public void WriteJson(object instance, IValueWriter writer) { switch (instance) { case null: writer.Null(); break; case bool value: writer.Bool(value); break; case int value: writer.Int(value); break; case long value: writer.Long(value); break; case float value: writer.Double(value); break; case double value: writer.Double(value); break; case string value: writer.String(value); break; case IReadOnlyDictionary <string, object> dict: var obj = writer.Object(); foreach (var kv in dict) { WriteJson(kv.Value, obj.Name(kv.Key)); } obj.End(); break; case IReadOnlyDictionary <object, object> dict: var obj1 = writer.Object(); foreach (var kv in dict) { WriteJson(kv.Value, obj1.Name(kv.Key.ToString())); } obj1.End(); break; case IEnumerable <object> list: var arr = writer.Array(); foreach (var o in list) { WriteJson(o, arr); } arr.End(); break; default: throw new ArgumentException(string.Format("ConvertSimpleTypes does not support type {0}", instance.GetType())); } }