Deserializing heterogenous JSON array into covariant List using Json.NET

Here is an example using CustomCreationConverter. public class JsonItemConverter : Newtonsoft.Json.Converters.CustomCreationConverter<Item> { public override Item Create(Type objectType) { throw new NotImplementedException(); } public Item Create(Type objectType, JObject jObject) { var type = (string)jObject.Property(“valueType”); switch (type) { case “int”: return new IntItem(); case “string”: return new StringItem(); } throw new ApplicationException(String.Format(“The given vehicle type {0} is … Read more

What is the use of @Serial annotation as of Java 14

What I don’t understand, does the annotation affect the de/serialization itself No. Its retention is ‘source’, so it’s discarded after compilation. The bytecode will contain no trace of it. It has no way to influence runtime behaviour (besides possibly compile-time code generation, which does not happen). Like @Override, it is optional and is supposed to … Read more

Jackson – Deserialising JSON string – TypeReference vs TypeFactory.constructCollectionType

After constructing JavaType, both call same deserialization functionality, so the only difference is the way generic type is handled. Second one is fully static, so type must be known in compile type, and can not vary. So it is similar to using basic Class literal. First one is dynamic, so it can be used to … Read more

Json.NET: Deserializing nested dictionaries

I found a way to convert all nested objects to Dictionary<string,object> by providing a CustomCreationConverter implementation: class MyConverter : CustomCreationConverter<IDictionary<string, object>> { public override IDictionary<string, object> Create(Type objectType) { return new Dictionary<string, object>(); } public override bool CanConvert(Type objectType) { // in addition to handling IDictionary<string, object> // we want to handle the deserialization of … Read more

Deserialize XML To Object using Dynamic

You may want to try this. string xml = @”<Students> <Student ID=””100″”> <Name>Arul</Name> <Mark>90</Mark> </Student> <Student> <Name>Arul2</Name> <Mark>80</Mark> </Student> </Students>”; dynamic students = DynamicXml.Parse(xml); var id = students.Student[0].ID; var name1 = students.Student[1].Name; foreach(var std in students.Student) { Console.WriteLine(std.Mark); } public class DynamicXml : DynamicObject { XElement _root; private DynamicXml(XElement root) { _root = root; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)