serialization

Custom DateTime serialization with Json.Net

℡╲_俬逩灬. 提交于 2020-01-04 01:48:31
问题 I'm trying unsuccessfully to create custom DateTime converter. The problem: I have many objects to serialize, some of the containing property of DateTime with DateTime.MinValue in it. I want to serialize it as null. But all the solution that I foud asking to decorate the proper inside the object (I can't do it) Other solution that I found below, is to create converter, As far as I can understand, this convertor works only DateTime object returned explicitly and not inside other object. Please

Unserialize - Error at offset 0 of 64 bytes

守給你的承諾、 提交于 2020-01-04 01:00:33
问题 Getting this error : echo $addressStr; $address = unserialize($addressStr); Echo returns 2:{i:0;s:18:"address:1,NN15 6TU";i:1;s:18:"address:8,NN15 6TU";} Error returns Notice: unserialize() [function.unserialize]: Error at offset 0 of 64 bytes in C:\wamp\www\guild_service\server\map_view.php on line 115 回答1: Your string is indeed something missing. I think it may need 'a:' in the front 来源: https://stackoverflow.com/questions/7336311/unserialize-error-at-offset-0-of-64-bytes

exception: boost::archive::archive_exception at memory location

↘锁芯ラ 提交于 2020-01-03 19:40:42
问题 When I try to deserialize binary data I get this: exception: boost::archive::archive_exception at memory location write: std::ofstream ofs(savePath); boost::archive::binary_oarchive out_arch(ofs); out_arch << mData; ofs.close(); read: std::ifstream ifs(loadPath); boost::archive::binary_iarchive in_arch(ifs); in_arch >> _mData; When i use text_iarchive \text_oarchive work fine. Serialized data structure mData is ColorMatrix<std::map<int, float>> mData; #include <algorithm> #include <memory>

Why does this code give two different outputs for (what appears to be) the same inputs?

霸气de小男生 提交于 2020-01-03 19:07:26
问题 I'm trying to program some AI for a game of checkers. My program is saying there are 0 moves for the white player, even though I know there are. The GetValidMoves() function is tested, and works in other areas of the code. To try and isolate the program I saved out the problematic board-state then loaded it back up to see if I would get the same problem: using(Stream s = File.Open("board.dat", FileMode.Create)) { var bf = new BinaryFormatter(); bf.Serialize(s, board); } Debug.WriteLine(board

How to serialize\deserialize a property where the property name is dependent on the data

泪湿孤枕 提交于 2020-01-03 17:47:47
问题 I'm trying to get the following json (see below) deserialized (using newtonsoft json serializer) and the problem is the variable named "2010-12" it is obviously dependent on the data returned - it represents a month and next month the value will change to "2010-01". Any ideas on how i could handle this with the following class? [JsonObject(MemberSerialization.OptIn)] public class Crimes { [JsonProperty()] public Month Month { get; set; } } Example JSON instance: { "commentary": null, "crimes"

How to serialize\deserialize a property where the property name is dependent on the data

筅森魡賤 提交于 2020-01-03 17:47:28
问题 I'm trying to get the following json (see below) deserialized (using newtonsoft json serializer) and the problem is the variable named "2010-12" it is obviously dependent on the data returned - it represents a month and next month the value will change to "2010-01". Any ideas on how i could handle this with the following class? [JsonObject(MemberSerialization.OptIn)] public class Crimes { [JsonProperty()] public Month Month { get; set; } } Example JSON instance: { "commentary": null, "crimes"

jsonrpc4j: How to add type info to parameters?

左心房为你撑大大i 提交于 2020-01-03 17:13:06
问题 I am using jsonrpc4j and got stuck. I made a little example to show my problem: Abstract class: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) @JsonSubTypes(value = { @JsonSubTypes.Type(value = Walnut.class) }) public abstract class Nut { } Concrete subclass: public class Walnut extends Nut { } Interface for the service: public interface ServiceInterface { public Nut getNut(); public void setNut(Nut nut); } The service itself: public class Service implements ServiceInterface { public Nut getNut()

Deserialize JSON Object to .Net object with NewtonSoft

孤人 提交于 2020-01-03 16:51:23
问题 I got a json Object that i want to deserialize to its .Net type without casting it. I think i read somewhere in the doc that you can pass an attribute into the json to tells to the deserializer the .Net object type that it can try to cast. I can't find the where i read this. I want to avoid use of var myNewObject = JsonConvert.DeserializeObject<MyClass>(json); To get something like this MyClass myNewObject = JsonConvert.DeserializeObject(json); I got my json object from an HttpRequest and

Do i need to implement Serializable for model classes while using GSON(serialization/deserialization library)

为君一笑 提交于 2020-01-03 16:50:49
问题 I have used default HttpUrlConnection class to make api calls and GSON to convert Java Objects into json request and json response into equivalent Java object.I have created various models(pojo class) to convert the request/response to model objects.My doubt is that is it ideal to implement Serializable to all those models since GSON is serialization/deserialization library? public class Contact implements Serializable { private String name; private String email; public String getName() {

How to edit a serialized hash column in form textarea

独自空忆成欢 提交于 2020-01-03 16:22:25
问题 I have a serialized column in Company model: class Company < ActiveRecord::Base serialize :names Ideally I want it to store different names like this in the database: --- short: bestbuy long: bestbuy ltd. Currently in my company#edit page, I have a text area for it: <%= f.text_area :names %> If I have that YAML in the database, it will be displayed in the browser as: {"short"=>"bestbuy", "long"=>"bestbuy ltd."} However when I submit it, in the database it became: --- ! '{"short"=>"bestbuy",