How to remove k__BackingField from json when Deserialize
Remove [Serializable] from your class
Remove [Serializable] from your class
Your xml has multiple root elements, this is not allowed for valid xml. If you change it to the format, this should work. <?xml version=”1.0″?> <Users> <user></user> <user></user> </Users>
If your are using DataContract serialization then you can override its default behaviour using the OnDeserialized attribute. From MSDN: When applied to a method, specifies that the method is called during deserialization of an object in an object graph. The order of deserialization relative to other objects in the graph is non-deterministic. Here is my … Read more
You may implement a JsonDeserializer and use it while parsing your Json value to a Java instance. I’ll try to show it with a code which is going to give you the idea: 1) Define your custom JsonDeserializer class which creates different instance of classes by incoming json value’s id property: class MyTypeModelDeserializer implements JsonDeserializer<MyBaseTypeModel> … Read more
For this purpose you need to pass additional info in JSON: @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property=”@type”) class Base { … } Then on serialization it will add @type field: objectMapper.registerSubtypes( new NamedType(ConcreteAAdapter.class, “ConcreteA”), new NamedType(ConcreteBAdapter.class, “ConcreteB”), new NamedType(ConcreteCAdapter.class, “ConcreteC”) ); // note, that for lists you need to pass TypeReference explicitly objectMapper.writerWithType(new TypeReference<List<Base>>() {}) .writeValueAsString(someList); { “@type” … Read more
You need to create a class that holds the user values, just like the response class User. Add a property to the Response class ‘user’ with the type of the new class for the user values User. public class Response { public string id { get; set; } public string text { get; set; } … Read more
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
You can do this using Jackson: mapper.readerForUpdating(object).readValue(json); See also Merging Two JSON Documents Using Jackson
This is the solution outlined by Manoj: If you want to suppress serialization of a specific property Foo, but still be able to deserialize it, you can add a method public bool ShouldSerializeFoo() that always returns false. Example: public class Circle2 { public double Diameter { get; set; } public double Radius { get { … Read more
The simplest way is deserialize array of key-value pairs to IDictionary<string, string>: public class SomeData { public string Id { get; set; } public IEnumerable<IDictionary<string, string>> Data { get; set; } } private static void Main(string[] args) { var json = “{ \”id\”: \”123\”, \”data\”: [ { \”key1\”: \”val1\” }, { \”key2\” : \”val2\” } … Read more