public static void Serializer(object untypedInput, ISerializationContext context, Type expected) { var type = untypedInput.GetType(); var serialized = JsonSerializer.Serialize(untypedInput); //TODO: differentiate between activities defined in Orleans.Workflows and activities defined in other assemblies (no need to compile/decompile) SerializationManager.SerializeInner(type.ToSourceCode(), context); SerializationManager.SerializeInner(serialized, context); }
public void Deserialize_InObject() { var json = "{\"Interval\":\"2012-01-02/2013-06-07\"}"; var testObject = JsonSerializer.Deserialize <TestObject>(json, Resolver); var interval = testObject.Interval; var startLocalDate = new LocalDate(2012, 1, 2); var endLocalDate = new LocalDate(2013, 6, 7); var expectedInterval = new DateInterval(startLocalDate, endLocalDate); Assert.Equal(expectedInterval, interval); }
public void Serialize_InObject() { var startLocalDate = new LocalDate(2012, 1, 2); var endLocalDate = new LocalDate(2013, 6, 7); var dateInterval = new DateInterval(startLocalDate, endLocalDate); var testObject = new TestObject { Interval = dateInterval }; var json = JsonSerializer.ToJsonString(testObject, Resolver); var expectedJson = "{\"Interval\":\"2012-01-02/2013-06-07\"}"; Assert.Equal(expectedJson, json); }
public static IEnumerable <(WriteObject, WriteObject)> GetModified(string firstRunId, string secondRunId) { var col = db?.GetCollection <WriteObject>("WriteObjects"); var list = new ConcurrentBag <(WriteObject, WriteObject)>(); //GetWriteObjects(firstRunId).AsParallel().ForAll(WO => foreach (var WO in GetWriteObjects(firstRunId)) { Log.Information(JsonSerializer.ToJsonString(WO)); var secondItem = col?.FindOne(Query.And(Query.EQ("RunId", secondRunId), Query.EQ("IdentityHash", WO.Identity), Query.Not("InstanceHash", WO.InstanceHash))); if (secondItem is WriteObject WO2) { list.Add((WO, WO2)); } } //}); return(list); }
//public static IEnumerable<WriteObject> GetMissingFromFirst2(string firstRunId, string secondRunId) //{ // var col = db.GetCollection<WriteObject>("WriteObjects"); // var list = new ConcurrentBag<WriteObject>(); // var Stopwatch = System.Diagnostics.Stopwatch.StartNew(); // var identityHashes = db.Execute($"SELECT IdentityHash FROM WriteObjects WHERE RunId = @0", // new BsonDocument // { // ["0"] = secondRunId // }); // Parallel.ForEach(identityHashes.ToEnumerable(), IdentityHash => // { // if (WriteObjectExists(firstRunId, IdentityHash["IdentityHash"].AsString)) // { // list.Add(GetWriteObject(secondRunId, IdentityHash.AsString)); // } // }); // Stopwatch.Stop(); // var t = TimeSpan.FromMilliseconds(Stopwatch.ElapsedMilliseconds); // var answer = string.Format(CultureInfo.InvariantCulture, "{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", // t.Hours, // t.Minutes, // t.Seconds, // t.Milliseconds); // Log.Debug("Completed getting WriteObjects for {0} in {1}", secondRunId, answer); // return list; //} public static IEnumerable <WriteObject> GetMissingFromFirst(string firstRunId, string secondRunId) { var col = db?.GetCollection <WriteObject>("WriteObjects"); var list = new ConcurrentBag <WriteObject>(); var wos = col?.Find(x => x.RunId == secondRunId) ?? Array.Empty <WriteObject>(); //wos.AsParallel().ForAll(wo => foreach (var wo in wos) { Log.Information($"{firstRunId},{JsonSerializer.ToJsonString(wo)}"); if (col?.Exists(x => x.Identity == firstRunId && x.RunId == wo.Identity) == true) { list.Add(wo); } } //}); return(wos ?? new List <WriteObject>()); }
private void Utf8JsonSample() { // UTF8Json : neuecc氏作、JsonUtilityと同様速い上に汎用的 // Dose'nt work on HoloLens2 (IL2CPPxARM64) { var target = new PersonSerializableClassField { id = 100, addresses = new AddressSerializableClassField[] { new AddressSerializableClassField { zipcode = 1002321, address = "hoge" }, new AddressSerializableClassField { zipcode = 1008492, address = "fuga" }, }, }; { var serialized = JsonSerializer.ToJsonString(target); Debug.Log(serialized); var deserialized = JsonSerializer.Deserialize <PersonSerializableClassField>(serialized); Debug.Log(deserialized.ToString()); } { var serialized = JsonSerializer.Serialize(target); Debug.Log(Convert.ToBase64String(serialized)); var tmp = System.Text.Encoding.UTF8.GetString(serialized); Debug.Log(tmp); var deserialized = JsonSerializer.Deserialize <PersonSerializableClassField>(serialized); Debug.Log(deserialized.ToString()); } } { var target = new PersonPlaneClassProperty { Id = 200, Addresses = new AddressPlaneClassProperty[] { new AddressPlaneClassProperty { Zipcode = 2003921, Address = "hoge" }, new AddressPlaneClassProperty { Zipcode = 2002955, Address = "fuga" }, }, }; var serialized = JsonSerializer.Serialize(target); Debug.Log(Convert.ToBase64String(serialized)); var tmp = System.Text.Encoding.UTF8.GetString(serialized); Debug.Log(tmp); var deserialized = JsonSerializer.Deserialize <PersonPlaneClassProperty>(serialized); Debug.Log(deserialized.ToString()); } { var target = new AddressRenamedProperty { Zipcode = 3003924, Address = "foobar", TelephoneNumber = "0312345678", }; var serialized = JsonSerializer.Serialize(target); Debug.Log(Convert.ToBase64String(serialized)); var tmp = System.Text.Encoding.UTF8.GetString(serialized); Debug.Log(tmp); var deserialized = JsonSerializer.Deserialize <AddressRenamedProperty>(serialized); Debug.Log(deserialized.ToString()); } }
public static void Set <T>(this ISession session, string key, T value) { JsonSerializer.SetDefaultResolver(StandardResolver.AllowPrivateCamelCase); session.SetString(key, JsonSerializer.ToJsonString(value)); }
public static Task WriteJsonAsync <T>(this HttpResponse response, T value) { response.ContentType = JsonContentType; return(JsonSerializer.SerializeAsync(response.Body, value, JsonFormatterResolver)); }