public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { Dictionary<string, object> filterDict = serializer.Deserialize<Dictionary<string, object>>(reader); Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(filterDict.First().Value.ToString()); string filterName = filterDict.First().Key; SynonymTokenFilter filter = null; if (fieldDict.ContainsKey(_SYNONYMS)) { filter = new SynonymTokenFilter(filterName, JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_SYNONYMS))); } else if (fieldDict.ContainsKey(_SYNONYMS_PATH)) { filter = new SynonymTokenFilter(filterName, fieldDict.GetString(_SYNONYMS_PATH)); } else { throw new RequiredPropertyMissingException(_SYNONYMS + "/" + _SYNONYMS_PATH); } TokenFilterBase.Deserialize(filter, fieldDict); filter.Expand = fieldDict.GetBool(_EXPAND, SynonymTokenFilter._EXPAND_DEFAULT); filter.IgnoreCase = fieldDict.GetBool(_IGNORE_CASE, SynonymTokenFilter._INGORE_CASE_DEFAULT); return filter; }
public void PASS_Create() { SynonymTokenFilter filter = new SynonymTokenFilter("name", "path") { Version = 2.4 }; Assert.IsNotNull(filter); Assert.AreEqual("name", filter.Name); Assert.AreEqual(2.4, filter.Version); Assert.AreEqual("path", filter.SynonymsPath); }
public void PASS_Serialize() { SynonymTokenFilter filter = new SynonymTokenFilter("name", "path") { Version = 2.4 }; string json = JsonConvert.SerializeObject(filter); Assert.IsNotNull(json); string expectedJson = "{\"name\":{\"type\":\"synonym\",\"version\":2.4,\"synonyms_path\":\"path\"}}"; Assert.AreEqual(expectedJson, json); }