public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { serializer.NullValueHandling = NullValueHandling.Ignore; if (IsMapType(objectType)) { IDictionary list = new Dictionary<Object, Object>(); serializer.Populate(reader, list); return list.ConvertMap(objectType); } else if (IsException(objectType)) { Object exceptionObject = Activator.CreateInstance(HelpMethods.ImplementTypeDynamicly(objectType, typeof(IJavaException))); serializer.Populate(reader, exceptionObject); return exceptionObject; } Type typeWithIOpenEngSBModel; if (alreadyExtendedTypes.ContainsKey(objectType.Name)) { typeWithIOpenEngSBModel = alreadyExtendedTypes[objectType.Name]; } else { typeWithIOpenEngSBModel = HelpMethods.ImplementTypeDynamicly(objectType, typeof(IOpenEngSBModel)); alreadyExtendedTypes.Add(objectType.Name, typeWithIOpenEngSBModel); } Object modelWithOpenEngsbModelTail = Activator.CreateInstance(typeWithIOpenEngSBModel); serializer.Populate(reader, modelWithOpenEngsbModelTail); return modelWithOpenEngsbModelTail; }
public void TestIfMapIsRecognizedAndIfVariablesAreDetectedCorrectlyAndCorrectConvertedFromJsonToObject() { IDictionary result = new Dictionary<String, String>(); Entry1[] entry = new Entry1[] { new Entry1() { key = "Test", value = 123 } }; result.Add("123", new JsonMarshaller().MarshallObject(entry)); EntryWithEntryParameter[] arrays = (EntryWithEntryParameter[])result.ConvertMap(typeof(EntryWithEntryParameter)); Assert.IsTrue(arrays[0].key.Equals("123")); Assert.IsTrue(arrays[0].value[0].key.Equals("Test")); }
public void TestConvertingWithExtendedMethodDictionaryToEntry1WhereTheReturnTypeIsIndicatedAsType() { Dictionary<Object, Object> test = new Dictionary<Object, Object>(); test.Add("1", 11); test.Add("21", 111); Entry1[] result = (Entry1[])test.ConvertMap(typeof(Entry1)); foreach (Entry1 e1 in result) { Assert.IsTrue(test.ContainsKey(e1.key)); Assert.AreEqual(test[e1.key], e1.value); } }
public void TestConvertingWithExtendedMethodDictionaryToEntry1() { Dictionary<Object, Object> test = new Dictionary<Object, Object>(); test.Add("1", 11); test.Add("21", 111); Entry1[] result = test.ConvertMap<Entry1>(); foreach (Entry1 e1 in result) { Assert.IsTrue(test.ContainsKey(e1.key)); Assert.AreEqual<Object>(test[e1.key], e1.value); } }
public void TestConvertIDictionaryToMap() { IDictionary result = new Dictionary<String, int>(); result.Add("Test", 123); Entry1[] arrays = (Entry1[])result.ConvertMap(typeof(Entry1[])); }
public void TestConvertDictionaryToEntry1WithParameterTypeAreEntry1AndInJsonFormat() { // This Test case checks if an object that is not an array is not recognized as Map and converted correctly IDictionary result = new Dictionary<String, String>(); Entry1 keyEntry = new Entry1 { key = "Test", value = 123 }; Entry1 valueEntry = new Entry1 { key = "ValueTest", value = 111 }; result.Add(marshaller.MarshallObject(keyEntry), marshaller.MarshallObject(valueEntry)); EntryWithAllEntryParameter[] arrays = (EntryWithAllEntryParameter[])result.ConvertMap(typeof(EntryWithAllEntryParameter)); Assert.AreEqual<String>(arrays[0].key.key, keyEntry.key); Assert.AreEqual<int>(arrays[0].key.value, keyEntry.value); Assert.AreEqual<String>(arrays[0].value.key, valueEntry.key); Assert.AreEqual<int>(arrays[0].value.value, valueEntry.value); }