deserialization

Runtime error Attempting to deserialize an empty stream

依然范特西╮ 提交于 2019-12-14 03:02:54
问题 I am trying to deserialize an list of string from a file. Here my code FileStream filestream = new FileStream(@"D:\cache.bin", FileMode.OpenOrCreate); try { BinaryFormatter binformat = new BinaryFormatter(); _cacheFileList = (List<string>)binformat.Deserialize(filestream); } catch (SerializationException ex) { Console.WriteLine(ex.Message); } finally { filestream.Close(); } I am getting a Runtime error. Attempting to deserialize an empty stream. 回答1: If you want support for empty files, first

Jackson ContextualDeserializer does not deserialize all fields

我们两清 提交于 2019-12-14 02:30:44
问题 I'm implementing a custom jackson deserializer for one of my entities. My entity is the following: @Value @JsonDeserialize @AllArgsConstructor public class TestModel { private final FieldUpdate<UUID> field1Update; private final FieldUpdate<UUID> field2Update; private final FieldUpdate<String> field3Update; public String toString() { return "TestModel. Field1="+(field1Update != null ? field1Update.toString() : null)+ " Field2="+(field2Update != null ? field2Update.getClass().getName() : null)

Different classes with same serialversion uid

狂风中的少年 提交于 2019-12-14 02:15:33
问题 I am having a strange doubt. All I want to know is, suppose if I have two classes, ( 100% same structure ) in two different locations (packages or projects), and I take care of generating the same serialVersionUID for both , can I safely say it's right to serialize using one class and de-serialize using another? P.S. I understand that it's not good to keep the same class in two separate places, but that's not the question right now. Thanks a ton. 回答1: ObjectInputStream will read the original

How to serialize/de-serialize a custom DataSet

旧城冷巷雨未停 提交于 2019-12-14 01:20:32
问题 I have a winforms app that uses a strongly typed custom DataSet for holding data for processing. It gets populated with data from a database. I have a user control that takes any custom dataset and displays the contents in a data grid. This is used for testing and debugging. To make the control reusable, I treat the custom dataset as a normal System.Data.DataSet. I have extended the control to allow the dataset to be saved to an XML file and also load previously saved XML files. What I'm now

I have deserialized C# class and i want to save it sqlite using xamarin forms PCL

时光总嘲笑我的痴心妄想 提交于 2019-12-13 20:53:19
问题 The deserialized class need to be store locally in sqlite database. I am using xamarin forms PCL , the metadata need to save and retrieve locally in database. I am not able to understand how can we save the deserialized C# class into database. 回答1: As the comments have pointed out, using CreateTable will handle that for you. Taking from the Xamarin.Forms sample: public TodoItemDatabase() { database = DependencyService.Get<ISQLite> ().GetConnection (); // create the tables database.CreateTable

JsonConvert string to Collection

倖福魔咒の 提交于 2019-12-13 20:10:09
问题 I get this json format from an API: "url_service": "", "Description": null, "Target": "5,6", "Category ": "2" I'm trying to deserialize the json into a model. The trouble is with the "Target" field which is supposed to be an ICollection of int. Here is my model: public string Description{ get; set; } public ICollection<int> Target{ get; set; } public int Category { get; set; } Is there a way to process the Json before it gets serialised in order to make a collection out of the comma separated

How to deserialize to property by attribute name and inner xml

六月ゝ 毕业季﹏ 提交于 2019-12-13 17:38:12
问题 I have an xml like this: <employees> <employee id="11629"> <field id="displayName">First Last</field> <field id="email">test@test.com</field> </employee> </employees> and I created a class: public class Employee { [XmlAttribute("id")] public string Id { get; set; } public string DisplayName { get; set; } public string Email { get; set; } } For Id everything works perfectly, but I can't figure out how but attribute we can set value to DisplayName property. Please help. 回答1: You may try this:

ElementListUnion - Simple xml giving duplicate annotation for generic list objects

人走茶凉 提交于 2019-12-13 16:37:39
问题 I am trying to deserialize a List field using elementlistunion Customer.java @ElementListUnion({ @ElementList(inline = false, type = Thing.class), @ElementList(inline = false, type = AnotherThing.class) }) List<Object> things = new ArrayList<Object>(); where Thing and AnotherThing are 2 POJO's.But Iam getting the following exception 03-21 18:56:31.940: E/AndroidRuntime(2289): Caused by: org.simpleframework.xml.core.PersistenceException: Duplicate annotation of name 'things' on @org

Jackson Default Typing for object containing a field of Map<String, Object>

随声附和 提交于 2019-12-13 15:23:41
问题 So I've been trying to get Jackson to serialize/deserialize one object I have which is esentially of the structure: MyObject { String a; Map<String, Object> map; } where map can hold nested maps or 'primitive' values (String, Integer, Long, Double...) Obviously, as the type information is required to correctly deserialize this I've had to tell Jackson to do this - for which I've used default typing: return new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

Deserialize a Dynamic JSON Array on C# WebForm

天大地大妈咪最大 提交于 2019-12-13 13:16:12
问题 Hi I am generating a JSON on my API that I am trying to use on codebehind C# in my web application but I cannot deserialize well. My JSON has an object with JSON arrays and the element inside the array are dynamic so I cannot create a fixed class with those items becuase my JSON can have N ITEMS. { "MAINOBJET": [{ "ITEM1": "23800", "ITEM2": "Dahl; Police", "ITEM3": "test@test.net" }, { "ITEM1": "23802", "ITEM2": "Steve ; Police", "ITEM3": "test2@test.net" }] } So how can I deserialize it to a