deserialization

Initialize private readonly fields after Deserializing

折月煮酒 提交于 2019-12-28 06:44:08
问题 I need to initialize private readonly field after Deserialization. I have folowing DataContract: [DataContract] public class Item { public Item() { // Constructor not called at Deserialization // because of FormatterServices.GetUninitializedObject is used // so field will not be initialized by constructor at Deserialization _privateReadonlyField = new object(); } // Initialization will not be called at Deserialization (same reason as for constructor) private readonly object

Json deserialization into another class hierarchy using Jackson

懵懂的女人 提交于 2019-12-28 03:40:05
问题 Now i'm working with Jackson and i have some questions about it. First of all. I have two services, first is data collecting and sending service and second receive this data and, for example, log it into a file. So, first service has class hierarchy like this: +----ConcreteC | Base ----+----ConcreteA | +----ConcreteB And second service has class hierarchy like this: ConcreteAAdapter extends ConcreteA implements Adapter {} ConcreteBAdapter extends ConcreteB implements Adapter {}

Polymorphism in jackson annotations: @JsonTypeInfo usage

人走茶凉 提交于 2019-12-27 17:07:57
问题 I would like to know if @JsonTypeInfo annotation can be used for interfaces. I have set of classes which should be serialized and deserialized. Here is what I'm trying to do. I have two implementation classes Sub1 , Sub2 implementing MyInt . Some of the model classes have the interface reference for the implementation types. I would like to deserialize the objects based on polymorphism @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=As.WRAPPER_OBJECT) @JsonSubTypes({ @Type(name="sub1", value

Deserializing Generic Types with GSON

走远了吗. 提交于 2019-12-27 17:04:15
问题 I have some problems with implementation of Json Deserialization in my Android application (with Gson library) I've made class like this public class MyJson<T>{ public List<T> posts; } And Deserialization call is: public class JsonDownloader<T> extends AsyncTask<Void, Void, MyJson<T>> { ... protected MyJson<T> doInBackground(Void... params) { ... Reader reader = new InputStreamReader(content); GsonBuilder gson = new GsonBuilder(); Type collectionType = new TypeToken<MyJson<T>>() {}.getType();

Deserializing Generic Types with GSON

北战南征 提交于 2019-12-27 17:03:24
问题 I have some problems with implementation of Json Deserialization in my Android application (with Gson library) I've made class like this public class MyJson<T>{ public List<T> posts; } And Deserialization call is: public class JsonDownloader<T> extends AsyncTask<Void, Void, MyJson<T>> { ... protected MyJson<T> doInBackground(Void... params) { ... Reader reader = new InputStreamReader(content); GsonBuilder gson = new GsonBuilder(); Type collectionType = new TypeToken<MyJson<T>>() {}.getType();

VB.net JSON Deserialize

我的梦境 提交于 2019-12-27 11:46:34
问题 I've got the following JSON string to deserialize: [{"application_id":"1","application_package":"abc"},{"application_id":"2","application_package":"xyz"}] I'm using DataContractJsonSerializer method. It is made up of array of items and I couldn't find an example using VB.Net that can deserialize this structure. I have the following Application class to store this information: <DataContract(Namespace:="")> _ Public Class ApplicationItem <DataMember(Name:="application_id")> Public Property

VB.net JSON Deserialize

江枫思渺然 提交于 2019-12-27 11:46:01
问题 I've got the following JSON string to deserialize: [{"application_id":"1","application_package":"abc"},{"application_id":"2","application_package":"xyz"}] I'm using DataContractJsonSerializer method. It is made up of array of items and I couldn't find an example using VB.Net that can deserialize this structure. I have the following Application class to store this information: <DataContract(Namespace:="")> _ Public Class ApplicationItem <DataMember(Name:="application_id")> Public Property

Newtonsoft JSON Deserialize

北城余情 提交于 2019-12-27 10:53:09
问题 My JSON is as follows: {"t":"1339886","a":true,"data":[],"Type":[['Ants','Biz','Tro']]} I found the Newtonsoft JSON.NET deserialize library for C#. I tried to use it as follow: object JsonDe = JsonConvert.DeserializeObject(Json); How can I access to the JsonDe object to get all the "Type" Data? I tried it with a loop but it is not working because the object does not have an enumerator. 回答1: You can implement a class that holds the fields you have in your JSON class MyData { public string t;

JsonConvert.DeserializeObject<IEnumerable<Book>>

帅比萌擦擦* 提交于 2019-12-25 15:51:46
问题 I want to know why I get this error when I use these statements: string result = await client.GetStringAsync(RestUrl); return JsonConvert.DeserializeObject<IEnumerable<Book>>(result); Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[BookClient.Data.Book]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized

(de)serialising Nested Generics in Jackson

十年热恋 提交于 2019-12-25 15:15:17
问题 So I am seeking to deserialise and serialise an object using Jackson. The object has a hierarchy, and deep down in the hierachy there is a List<T> where T is either a String, or one of the Java number classes. Deserialising generic lists has been a common topic on these forums, and I know how to build a mapper that will deserialise or serialise a list using mapper.readValue. What I don't know how to do is make is so that when I call the mapper on the top level, which doesn't know explicitly