serialization

Can I Deserialize a JSON string that contains 0.0 in C#?

巧了我就是萌 提交于 2019-12-31 05:36:08
问题 The JSON I'm getting back from a webservice has an integer incorrectly represented as 0.0. My deserialization code looks like this: var serializer = new JsonSerializer(); var ret = serializer.Deserialize<T>(jsonTextReader); And I get an error like this: Input string '0.0' is not a valid integer. My question is, is there a way to specify a less strict deserialization method so that I can parse this string? EDIT: The web service returns no schema so I don't know why the deserializer tries to

Serializing a BitmapImage in WinRT

淺唱寂寞╮ 提交于 2019-12-31 05:30:05
问题 public static async Task SaveFileAsync(string FileName, T data) { MemoryStream memStream = new MemoryStream(); DataContractSerializer serializer = new DataContractSerializer(typeof(T)); serializer.WriteObject(memStream, data); StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); using (Stream stream = await file.OpenStreamForWriteAsync()) { memStream.Seek(0, SeekOrigin.Begin); await memStream.CopyToAsync(stream);

Serializing a list of objects to XDocument

会有一股神秘感。 提交于 2019-12-31 05:01:29
问题 I'm trying to use the following code to serialize a list of objects into XDocument, but I'm getting an error stating that "Non white space characters cannot be added to content " public XDocument GetEngagement(MyApplication application) { ProxyClient client = new ProxyClient(); List<Engagement> engs; List<Engagement> allEngs = new List<Engagement>(); foreach (Applicant app in application.Applicants) { engs = new List<Engagement>(); engs = client.GetEngagements("myConnString", app.SSN.ToString

protobuf.net & conditional serialization

别来无恙 提交于 2019-12-31 04:49:07
问题 We are using protobuf.net to serialize classes between mobile devices and back end services, but we now need to adjust what is sent back to the client based upon the 'context' of the user. We would typically do this by implementing the ISerializable interface and look at the context value to then decide what to serialize. Similarly in the constructor we would then deserialize the provided values. But it would appear that ISerializable isn't implemented/support (i can see why) for protobuf.net

How to exclude properties from JsonConvert.PopulateObject that don't exist in some base type or interface?

吃可爱长大的小学妹 提交于 2019-12-31 04:44:05
问题 Is it possible to define options to JsonConvert.PopulateObject to exclude fields given in a json, that does not exists in the target object's interface implementation? public interface IElementWriter { string Name { get; set; } } public interface IElementUpdateWriter : IElementWriter { string FirstName { get; set; } } public interface IElementInsertWriter : IElementWriter { DateTime? CreationDate { get; set; } } public class Element:IElementWriter, IElementInsertWriter, IElementUpdateWriter {

XML deserialization ignores properties out of alphabetical order

喜夏-厌秋 提交于 2019-12-31 04:28:07
问题 I have small problem - XML deserialization completely ignores items, which are out of alphabetic order. In example object (description in end of question), Birthday node is after FirstName node, and it is ignored and assigned default value after deserialization. Same for any other types and names (I had node CaseId of Guid type after node Patient of PatientInfo type, and after deserialization it had default value). I'm serializing it in one application, using next code: public static string

Deserialize JSON subdocument

走远了吗. 提交于 2019-12-31 04:08:06
问题 I'm calling the JIRA Rest API to recieve a list of Worklog Objects. The JSON I recieve looks like. { "startAt": 0, "maxResults": 1, "total": 1, "worklogs": [ { "self": "http://www.example.com/jira/rest/api/2/issue/10010/worklog/10000", "author": { "self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "displayName": "Fred F. User", "active": false }, "updateAuthor": { "self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred",

C# Deserialization xml file

青春壹個敷衍的年華 提交于 2019-12-31 03:42:06
问题 I try to deserialize xml file: <?xml version="1.0" encoding="utf-8"?> <XmlFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <OBJECTS ITEM="ItemValue" TABLE_NAME="TableExample"> </OBJECTS> </XmlFile> My deserialize class code looks like that: [Serializable] [XmlRoot("XmlFile")] public class SerializeObject { [XmlAttribute("ITEM")] public string Item { get; set; } [XmlAttribute("TABLE_NAME")] public string Table_Name { get; set; } } When I

serializing a list of KeyValuePair to XML

荒凉一梦 提交于 2019-12-31 03:38:08
问题 I am trying to serailize an Object into XML. Below is the XML format which I need. <parameters> <parameter> <key>Key1</key> <value>Value1</value> <key>Key2</key> <value>Value2</value> <key>Key3</key> <value>value3</value> </parameter> </parameters> Below is the Model I have created [Serializable] [XmlType("parameters")] public class parameters { public List<parameter<string,string>> parameter { get; set; } } [Serializable] [XmlType("parameter")] public class parameter<K,V> { public K key {

Jackson custom serializer serialize field twice if property name not equal field name

孤者浪人 提交于 2019-12-31 03:14:07
问题 If you use custom serialization, you can get an unexpected effect if property name not equal to field name. Why the field is serialized twice? My code sample: class Mode { @JsonProperty("mode") @JsonSerialize(using = ModeSerializer.class) private boolean isPublic; public Mode(boolean isPublic) { this.isPublic = isPublic; } public boolean isPublic() { return isPublic; } } Here my custom field serializer: class ModeSerializer extends JsonSerializer<Boolean> { @Override public void serialize