diff --git a/src/BirdsiteLive.ActivityPub/Models/Actor.cs b/src/BirdsiteLive.ActivityPub/Models/Actor.cs index 51dc41c..cbebba1 100644 --- a/src/BirdsiteLive.ActivityPub/Models/Actor.cs +++ b/src/BirdsiteLive.ActivityPub/Models/Actor.cs @@ -1,6 +1,7 @@ using System; -using System.Text.Json.Serialization; +using System.Collections.Generic; using Newtonsoft.Json; +using JsonConverter = Newtonsoft.Json.JsonConverter; namespace BirdsiteLive.ActivityPub { @@ -8,7 +9,8 @@ namespace BirdsiteLive.ActivityPub { //[JsonPropertyName("@context")] [JsonProperty("@context")] - public object[] context { get; set; } = new[] {"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1" }; + [JsonConverter(typeof(ContextArrayConverter))] + public string[] context { get; set; } = new[] { "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1" }; public string id { get; set; } public string type { get; set; } public string preferredUsername { get; set; } @@ -20,4 +22,37 @@ namespace BirdsiteLive.ActivityPub public Image icon { get; set; } public Image image { get; set; } } + + public class ContextArrayConverter : JsonConverter + { + public override bool CanWrite { get { return false; } } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var result = new List(); + + var list = serializer.Deserialize>(reader); + foreach (var l in list) + { + if (l is string s) + result.Add(s); + else + { + var str = JsonConvert.SerializeObject(l); + result.Add(str); + } + } + + return result.ToArray(); + } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + } } diff --git a/src/BirdsiteLive/Controllers/UsersController.cs b/src/BirdsiteLive/Controllers/UsersController.cs index bae8701..91c8d69 100644 --- a/src/BirdsiteLive/Controllers/UsersController.cs +++ b/src/BirdsiteLive/Controllers/UsersController.cs @@ -73,7 +73,7 @@ namespace BirdsiteLive.Controllers private Dictionary RequestHeaders(IHeaderDictionary header) { - return header.ToDictionary, string, string>(h => h.Key, h => h.Value); + return header.ToDictionary, string, string>(h => h.Key.ToLowerInvariant(), h => h.Value); } } } \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.ActivityPub.Tests/ActorTests.cs b/src/Tests/BirdsiteLive.ActivityPub.Tests/ActorTests.cs index 337eee6..628869c 100644 --- a/src/Tests/BirdsiteLive.ActivityPub.Tests/ActorTests.cs +++ b/src/Tests/BirdsiteLive.ActivityPub.Tests/ActorTests.cs @@ -16,6 +16,20 @@ namespace BirdsiteLive.ActivityPub.Tests var actor = JsonConvert.DeserializeObject(json); + } + + [TestMethod] + public void Serialize() + { + var obj = new Actor + { + type = "Person", + id = "id" + }; + + var json = JsonConvert.SerializeObject(obj); + + } } } \ No newline at end of file