public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { Dictionary<string, object> tokenDict = serializer.Deserialize<Dictionary<string, object>>(reader); Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(tokenDict.First().Value.ToString()); PathHierarchyTokenizer token = new PathHierarchyTokenizer(tokenDict.First().Key); TokenizerBase.Deserialize(token, fieldDict); token.BufferSize = fieldDict.GetInt64(_BUFFER_SIZE, PathHierarchyTokenizer._BUFFER_SIZE_DEFAULT); token.Delimeter = fieldDict.GetString(_DELIMITER, PathHierarchyTokenizer._DELIMITER_DEFAULT); token.Replacement = fieldDict.GetString(_REPLACEMENT, token.Delimeter); token.Reverse = fieldDict.GetBool(_REVERSE, PathHierarchyTokenizer._REVERSE_DEFAULT); token.Skip = fieldDict.GetInt64(_SKIP, PathHierarchyTokenizer._SKIP_DEFAULT); return token; }
public void PASS_Serialize() { PathHierarchyTokenizer token = new PathHierarchyTokenizer("name") { BufferSize = 512, Delimeter = ",", Replacement = ";", Reverse = true, Skip = 2, Version = 2.1 }; string json = JsonConvert.SerializeObject(token); Assert.IsNotNull(json); string expectedJson = "{\"name\":{\"type\":\"path_hierarchy\",\"version\":2.1,\"delimiter\":\",\",\"replacement\":\";\",\"buffer_size\":512,\"reverse\":true,\"skip\":2}}"; Assert.AreEqual(expectedJson, json); }
public void PASS_Create() { PathHierarchyTokenizer token = new PathHierarchyTokenizer("name") { BufferSize = 512, Delimeter = ",", Replacement = ";", Reverse = true, Skip = 2, Version = 2.1 }; Assert.IsNotNull(token); Assert.AreEqual("name", token.Name); Assert.AreEqual(2.1, token.Version); Assert.AreEqual((Int64)512, token.BufferSize); Assert.AreEqual(",", token.Delimeter); Assert.AreEqual(";", token.Replacement); Assert.AreEqual(true, token.Reverse); Assert.AreEqual((Int64)2, token.Skip); }