serialization

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

偶尔善良 提交于 2019-12-31 03:14:04
问题 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

Issue deserializing encrypted data using BinaryFormatter

廉价感情. 提交于 2019-12-31 03:09:03
问题 Here is my code: public static void Save<T>(T toSerialize, string fileSpec) { BinaryFormatter formatter = new BinaryFormatter(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); using (FileStream stream = File.Create(fileSpec)) { using (CryptoStream cryptoStream = new CryptoStream(stream, des.CreateEncryptor(key, iv), CryptoStreamMode.Write)) { formatter.Serialize(cryptoStream, toSerialize); cryptoStream.FlushFinalBlock(); } } } public static T Load<T>(string fileSpec) {

HttpWebRequest Won't Serialize

空扰寡人 提交于 2019-12-31 02:55:11
问题 I'm getting the following error when I try to Serialize an HttpWebRequest Type 'System.Net.KnownHttpVerb' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. Using .Net Framework 2.0 This is one of the properties that my class holds. It's a requirement to serialize it. HttpWebRequest is marked as Serializable so it supposed to Serialize 回答1: Well, if one of the contained objects is marked as non-serializable, I believe you're

How can I unserialize Symfony session from the file?

…衆ロ難τιáo~ 提交于 2019-12-31 02:53:07
问题 Symfony store session in the app/cache/dev/sessions/sess_{session_id} file in dev env. The file's content is something like: _sf2_attributes|a:0:{}_sf2_flashes|a:0:{}_sf2_meta|a:3:{s:1:"u";i:1396424236;s:1:"c";i:1396360957;s:1:"l";s:1:"0";}bbb|i:222;IsAuthorized|b:1; When I try to unserialize it with unserialize() function - I get FALSE . How can I unserilize this? 回答1: You can just use standard PHP session mechanism. You need to set up the directory where your sessions is stored ( app/cache

Class not serializable after methods are overridden

梦想的初衷 提交于 2019-12-31 02:44:04
问题 I override a createSocket() method in my test cases to pas in a mocked Socket. After doing this the objects aren't serializable anymore. Here's a example of what doesn't work. Foo.java import java.io.Serializable; public class Foo implements Serializable { private static final long serialVersionUID = 3109852436898487119L; public void bar() { System.out.println("Foo"); } } FooTest.java import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import

How to apply JsonExtensionData (Dictionary<string, JToken>) to another object with JSON.Net

一个人想着一个人 提交于 2019-12-31 02:43:10
问题 I came across this (seemingly usual) scenario but I could not find a satisfying solution. Maybe someone knows: For some reason I parse JSON and I allow the user to provide more key-value pairs than my class has properties. I store the arbitrary ones away like so: class MusterNode { // some definite property public string TypeName { get; set; } // takes the rest // see https://www.newtonsoft.com/json/help/html/DeserializeExtensionData.htm [JsonExtensionData] private Dictionary<string, JToken>

Maintain object references through Serialize/Deserialize

亡梦爱人 提交于 2019-12-31 02:18:24
问题 When serializing, I would like to serialize an object only once, then any references to that object should be serialized as a reference to the object. This is because, when I later deserialize the objects, I would like to maintain those references. To illustrate my goal, the code below should output "After Serialization: true". class Program { static void Main(string[] args) { MyObject obj = new MyObject() { Name = "obj" }; MyObject[] myObjs = new MyObject[] { obj, obj }; Console.WriteLine(

Serializing System.Drawing.Color in .NET

匆匆过客 提交于 2019-12-31 01:58:05
问题 I've used the default .NET serialization for a class with a System.Drawing.Color member. The code is now in use by people, and I need to add an extra member to the class, but still deserialize older versions. So I tried the standard way of doing this: The ISerializable interface, using SerializationInfo methods to get the int and string members. The problem: My class also has a System.Drawing.Color member, but SerializationInfo doesn't provide a "GetColor" method read this data type. I've

Issue with MVVMLight ViewModelBase public parameterless constructor in inherited base class for WP7 Tombstoning

柔情痞子 提交于 2019-12-31 01:46:10
问题 I am handling tombstoning in Wp7 by dumping my ViewModel into the PhoneApplicationService state (see this link for more info). My ViewModel (VM) inherits from the MVVM Light Toolkit (ViewModelBase) which has a protected parameterless constructor only. This causes the serilization to fail with: "The type 'GalaSoft.MvvmLight.ViewModelBase' cannot be deserialized in partial trust because it does not have a public parameterless constructor." Excuse my ignorance but serialization is new to me - I

Silverlight webservice call works in Studio but fails when run from website

戏子无情 提交于 2019-12-31 01:13:26
问题 We are building a Silverlight application and have calls to a Silverlight-WCF service. When running the application from Visual Studio everything works perfectly. When we deploy to the website and run the application we get the following error (or one much like it) every time we call the web-service. Message: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel