serialization

Deserialization not working on MemoryStream

霸气de小男生 提交于 2019-12-21 08:26:21
问题 //Serialize the Object MemoryStream ms = new MemoryStream(); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(ms , ObjectToSerialize); byte[] arrbyte = new byte[ms .Length]; ms.Read(arrbyte , 0, (int)ms .Length); ms.Close(); //Deserialize the Object Stream s = new MemoryStream(arrbyte); s.Position = 0; Object obj = formatter.Deserialize(s);//Throws an Exception s.Close(); If I try to Deserialize with the above way it gives the Exception as 'Binary stream '0' does not contain

“Invalid field in source data: 0” error with ProtoBuf-Net and Compact Framework

谁都会走 提交于 2019-12-21 07:44:50
问题 Is anyone aware of any issues when using ProtoBuf-Net to serialize/deserialize between compact framework and the full .Net framework? I have a class called LogData that I am serializing under compact framework 3.5, transmitting to a server (running .Net framework 4.0), which then deserializes. Sometimes it works and sometimes it throws the above error and I have yet to narrow it down to any specific cause. I've done many many tests with different values and can't seem to find any rhyme or

“Invalid field in source data: 0” error with ProtoBuf-Net and Compact Framework

馋奶兔 提交于 2019-12-21 07:41:13
问题 Is anyone aware of any issues when using ProtoBuf-Net to serialize/deserialize between compact framework and the full .Net framework? I have a class called LogData that I am serializing under compact framework 3.5, transmitting to a server (running .Net framework 4.0), which then deserializes. Sometimes it works and sometimes it throws the above error and I have yet to narrow it down to any specific cause. I've done many many tests with different values and can't seem to find any rhyme or

Remove “d1p1” namespace prefix in DataContractSerializer XML output

一曲冷凌霜 提交于 2019-12-21 07:34:32
问题 I'm using DatacontractSerializer to serialize my domainModel into a xml file. I'm getting output like below. <z:anyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:d1p1="DCSerialization_IGITApproach" i:type="d1p1:X" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <d1p1:Name z:Id="2">Ankit</d1p1:Name> <d1p1:PointsDictionary xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" z:Id="3" z:Size="1"> <d2p1:KeyValueOfstringPointsArrayq9VX7VJJ>

PHP - *fast* serialize/unserialize?

点点圈 提交于 2019-12-21 07:28:26
问题 I have a PHP script that builds a binary search tree over a rather large CSV file (5MB+). This is nice and all, but it takes about 3 seconds to read/parse/index the file. Now I thought I could use serialize() and unserialize() to quicken the process. When the CSV file has not changed in the meantime, there is no point in parsing it again. To my horror I find that calling serialize() on my index object takes 5 seconds and produces a huge (19MB) text file, whereas unserialize() takes unbearable

NotSerializableException for `Map[String, String]` alias

六月ゝ 毕业季﹏ 提交于 2019-12-21 07:28:10
问题 I'm trying to send an object to a remote actor and I got this exception: ERROR akka.remote.EndpointWriter - Transient association error (association remains live) java.io.NotSerializableException: scala.collection.immutable.MapLike$$anon$2 The object being serialized is a case class: case class LocationReport(idn: String, report: String, timestamp: Option[String], location: Attr, status: Attr, alarms: Attr, network: Attr, sensors: Attr) extends Message(idn) { val ts = timestamp getOrElse

How to use ShouldSerialize[MemberName]() method for a property of type Object?

拜拜、爱过 提交于 2019-12-21 07:19:11
问题 I have tried to prevent the property of type object with no new values assigned to its properties using ShouldSerialize Method in Newtonsoft.Json. But I dont know how to implement it, so please help me to solve this... Here is the sample code public class Sample1 { public String name{get;set;} public int Id{get;set;}; } And this is my Class containing the above class as one of its properties public class Container { public String Cname{get;set;} public Sample1 Sample{get;set;}; public bool

How to invoke another serializer from a custom Gson JsonSerializer?

为君一笑 提交于 2019-12-21 07:18:08
问题 I have my custom class User : class User { public String name; public int id; public Address address; public Timestamp created; } I'm now creating a custom JsonSerializer for User.class: @Override public JsonElement serialize(User src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); obj.addProperty("name", src.name); obj.addProperty("id", src.id); obj.addProperty("address", src.address.id); // Want to invoke another JsonSerializer (TimestampAdapter) for

What does BOOST_SERIALIZATION_NVP do when serializing object?

筅森魡賤 提交于 2019-12-21 07:06:22
问题 I am using boost.serialization. some sample code use BOOST_SERIALIZATION_NVP in serialize method: template<class Archive> void save(Archive & ar, const unsigned int version) const { ar & BOOST_SERIALIZATION_NVP(_from_prop); } I tried to google its functionality but nothing useful is found. what is the diff between ar & BOOST_SERIALIZATION_NVP(_from_prop) and ar & _from_prop? 回答1: BOOST_SERIALIZATION_NVP is a macro that expands (in your example) to: template<class Archive> void save(Archive &

Why does SerializationInfo not have TryGetValue methods?

非 Y 不嫁゛ 提交于 2019-12-21 07:02:59
问题 When implementing the ISerializable interface in C#, we provide a constructor which takes a SerializationInfo object, and then queries it with various GetInt32 , GetObject etc. methods in order to fill the fields of the object which we are trying to deserialize. One major reason to implement this interface, rather than just using the [Serializable] attribute, is for backwards compatibility: if we have added new fields to the class at some point, we can catch the SerializationException thrown