deserialization

Deserialize element value as string although it contains mixed content

雨燕双飞 提交于 2019-12-19 08:09:34
问题 Assuming an XML like this: <my:Root xmlns:my="http://foo/bar"> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml"> <div><h1>content</h1></div> </html> </my:FieldComplex> <my:Root> and a class like: [Serializable] [XmlType(AnonymousType = true, Namespace = "http://foo/bar")] [XmlRoot(ElementName = "Root", Namespace = "http://foo/bar", IsNullable = false)] public class MyRoot { public string FieldBasic { get; set; } public

Deserialization error: value cannot be null. Parameter name: type

岁酱吖の 提交于 2019-12-19 05:33:25
问题 I'm trying to deserialize a json response and am getting the value cannot be null error. Any help is really appreciated! I'm deserializing a lot of other json strings this way and have never run into this error. I'm not sure what's causing it. Thanks! Here is the code for the object: [Serializable] public class LocationResponse { public string authenticationResultCode { get; set; } public string brandLogoUri { get; set; } public string copyright { get; set; } public List<ResourceSet>

How to deserialize object in OpenJDK (Android 7+), which has been serialized in Apache Harmony (Android *-6)?

大憨熊 提交于 2019-12-19 03:58:56
问题 My app uses http://prevayler.org/ for persistence, piggybacking Java Object serialization. After upgrade to Android 7.0 (Nougat) users cannot open their data, since the deserialization does not work any more: java.io.StreamCorruptedException: invalid type code: 71 at java.io.ObjectInputStream.readString(ObjectInputStream.java:1647) at java.io.ObjectInputStream.readEnum(ObjectInputStream.java:1737) ... at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) at org.prevayler

Deserialize Xml with empty elements

你。 提交于 2019-12-19 03:14:04
问题 Consider the following XML: <a> <b>2</b> <c></c> </a> I need to deserialize this xml to an object. So, i wrote the following class. public class A { [XmlElement("b", Namespace = "")] public int? B { get; set; } [XmlElement("c", Namespace = "")] public int? C { get; set; } } Since i'm using nullables, i was expecting that, when deserialing the above xml, i would get an object A with a null C property. Instead of this, i get an exception telling the document has an error. 回答1: There's a

deserialize json field into plain string with gson

↘锁芯ラ 提交于 2019-12-18 21:52:30
问题 I am trying to deserialize a json object into a java bean. The main issue I am facing is that I'd like to treat the field object of the json string as a plain string, even if it contains a potentially correct json object. The json structure is like this: { "type":"user", "object":{ "id":"1", ...} } How can i tell gson to ignore the object value so that it doesn't get deserialized into an object? I'd like it only to be mapped to a plain String field in my bean so that I can dispose a proper

How to Serialize property of type ICollection<T> while using Entity Framework

家住魔仙堡 提交于 2019-12-18 19:09:17
问题 I have a class as shown below public class Survey { public Survey() { SurveyResponses=new List<SurveyResponse>(); } [Key] public Guid SurveyId { get; set; } public string SurveyName { get; set; } public string SurveyDescription { get; set; } public virtual ICollection<Question> Questions { get; set; } public virtual ICollection<SurveyResponse> SurveyResponses { get; set; } } The above code gives me following exception Cannot serialize member 'SurveyGenerator.Survey.Questions' of type 'System

How to handle deserialization of empty string into enum in json.net

旧巷老猫 提交于 2019-12-18 18:56:37
问题 I am deserializing json properties into an enum but I'm having issues handling cases when the property is an empty string. Error converting value "" to type 'EnrollmentState' I'm trying to deserialize the state property in a requiredItem . { "currentStage" : "Pre-Approved", "stages" : ["Applicant", "Pre-Approved", "Approved", "Enrolled"], "requiredItems" : [{ "id" : 1, "name" : "Documents", "state" : "" }, { "id" : 2, "name" : "Eligibility Verification", "state" : "complete" }, { "id" : 3,

Direct self-reference leading to cycle exception

烂漫一生 提交于 2019-12-18 18:55:22
问题 I have a class; something like the following: public abstract class ElasticSearchValue<T> { private Long txId; private Long currentTxId; private T previous; public Long getTxId() { return txId; } public void setTxId(Long txId) { this.txId = txId; } public Long getCurrentTxId() { return currentTxId; } public void setCurrentTxId(Long currentTxId) { this.currentTxId = currentTxId; } public Object getPrevious() { return previous; } public void setPrevious(T previous) { this.previous = previous; }

How to deserialize class without calling a constructor?

孤街醉人 提交于 2019-12-18 14:14:54
问题 I'm using Json.NET in my WCF data service. Here's my class (simplified): [DataContract] public class Component { public Component() { // I'm doing some magic here. } } How can I deserialize that class without invoking a constructor using JsonConvert.DeserializeObject ? Sorry if not clear, feel free to ask questions. 回答1: You could create a class that inherits from CustomCreationConverter and use FormatterServices.GetSafeUninitializedObject to create your object. It skips calling the

Hashmap slower after deserialization - Why?

a 夏天 提交于 2019-12-18 13:41:12
问题 I have a pretty large Hashmap (~250MB). Creating it takes about 50-55 seconds, so I decided to serialize it and save it to a file. Reading from the file takes about 16-17 seconds now. The only problem is that lookups seems to be slower this way. I always thought that the hashmap is read from the file into the memory, so the performance should be the same compared to the case when I create the hashmap myself, right? Here is the code I am using to read the hashmap into a file: File file = new