serialization

NotSerializableException on saving custom class

一曲冷凌霜 提交于 2020-01-04 03:27:09
问题 My two classes are designed too create an array of StudentData objects (name, Date Of Birth, and ID), that include a toString override to print out all variables. It then serializes the array and saves it to a file named studentdata.txt. It should then read the array from the file and reconstruct a new array object from this data, and print out each item in the array to the console. Am getting this error when attempting to complie... Exception in thread "main" java.io.NotSerializableException

NotSerializableException on saving custom class

蓝咒 提交于 2020-01-04 03:26:51
问题 My two classes are designed too create an array of StudentData objects (name, Date Of Birth, and ID), that include a toString override to print out all variables. It then serializes the array and saves it to a file named studentdata.txt. It should then read the array from the file and reconstruct a new array object from this data, and print out each item in the array to the console. Am getting this error when attempting to complie... Exception in thread "main" java.io.NotSerializableException

AppFabric Caching - What are its serialization and deserialization requirements for an object?

非 Y 不嫁゛ 提交于 2020-01-04 03:13:29
问题 Problem: When caching an instance of a class and immediately getting it back out of cache, i get the object back (its not null), but all of its properties / fields are null or defaults. _cacheHelper.PutInCache("testModuleControlInfoOne", mci); //mci has populated fields var mciFromCacheOne = _cacheHelper.GetFromCache("testModuleControlInfoOne"); //mciFromCacheOne now has null or default fields So I suspect the way the object is structured is the problem and AppFabric is not serializing the

Serialization problem

删除回忆录丶 提交于 2020-01-04 02:57:30
问题 The situation is like this : Main project A. and a class library B. A references B Project B has the classes that will be serialized. The classes are used in A. Now, the problem appears when from Project A I try to serialize the objects from B. An exception is thrown that says a class from A cannot be serialized. This is the strange part since in the classes in B I cant have a reference to those in A. (a circular dependency would be created). How can I track down the problem ? because the

WPF loading serialized image

笑着哭i 提交于 2020-01-04 02:54:34
问题 In an app I need to serialize an image through a binarywriter, and to get it in an other app to display it. Here is a part of my "serialization" code : FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write); BinaryWriter bin = new BinaryWriter(fs); bin.Write((short)this.Animations.Count); for (int i = 0; i < this.Animations.Count; i++) { MemoryStream stream = new MemoryStream(); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(Animations[i

DataContractJsonSerializer generic list containing element type's subtypes

柔情痞子 提交于 2020-01-04 02:53:13
问题 I'm going to use DataContractJsonSerializer for JSON serialization/deserialization. I have two object types in the JSON array and want them both to be deserialized into corresponding object types. Having the following class defnitions [DataContract] public class Post { [DataMember(Name = "content")] public String Content { get; set; } } [DataContract] public class User { [DataMember(Name = "user_name")] public String UserName { get; set; } [DataMember(Name = "email")] public String Email {

Convert json to datatable vb

百般思念 提交于 2020-01-04 02:46:08
问题 Good morning, today i was trying to convert my json to datatable. This is what i'm trying to do Dim webclient_server7 As New System.Net.WebClient Dim json_result As String = webclient_server7.DownloadString("http://myhost/api/mycontroller/GetQuery") Dim json_jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(json_result) Try Dim table As DataTable = JsonConvert.DeserializeObject(Of DataTable)(json_jsonstring) Catch ex As Exception MsgBox("An exception occured: " & ex.Message) End Try

Rails 3: Escape characters (\) appearing in part of JSON string

风格不统一 提交于 2020-01-04 02:30:55
问题 Anyone know why some of my json elements are being backslash( \ ) escaped while others are not? {"first":"John","last":"Smith","dogs":"[{\"name\":\"Rex\",\"breed\":\"Lab\"},{\"name\":\"Spot\",\"breed\":\"Dalmation\"},{\"name\":\"Fido\",\"breed\":\"Terrier\"}]"} Ideally I'd like NONE of them to be escaped... This was generated by overriding as_json in two models. Person has_many Dogs. #models/person.rb class Person < ActiveRecord::Base has_many :dogs def as_json(options={}) { :first => first,

C# [anonymous\generic] object to byte[] without BinaryFormatter [in .NET 4.5]?

喜欢而已 提交于 2020-01-04 02:15:14
问题 BinaryFormatter works great, but doesn't exist in Portable class libraries for .NET 4.5. I've read that it IS in .NET 4.6 Portable. I have not confirmed this because when I change to 4.6 in my project settings, I get a warning message that "4.5 will be automatically targeted" unless I de-select Silverlight, WindowsPhone, Windows Universal, Xamarin, etc), so I can only target .NET 4.6 Portable if I'm NOT targeting additional platforms, thus defeating the purpose. Here is my original

Deserialize string with Tuple key in C#

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 02:08:05
问题 I have a dictionary like this: var dict1 = new Dictionary<(int, int), int); dict1.add((1,2), 3); That is serialized to a string using: var s = JsonConvert.SerializeObject(dict1); // s = "{\"(1,2)\":\"3\"}"; When trying to deserialize the string using: var j = JsonConvert.DeserializeObject<Dictionary<(int, int), int>>(s); I get an error like: 'Could not convert string '(1,2)' to dictionary key type 'System.ValueTuple`2[System.Int32,System.Int32]'. Create a TypeConverter to convert from the