serialization

How to save a swift struct to file

≡放荡痞女 提交于 2020-01-01 06:00:36
问题 I want to use structs for the (very simple) model of my app. However NSKeyedArchiver only accepts objects (extending NSObjects ). Is there any good way to save a struct to a file? 回答1: A very simple approach I used sometimes. The quantity of code you need to write is no more then in the class/NSCoding scenario. First of all import the great SwiftyJSON lib. Let's start with a simple struct struct Starship { let name: String let warpSpeed: Bool let captain: String? init(name: String, warpSpeed:

How to save a swift struct to file

喜欢而已 提交于 2020-01-01 06:00:09
问题 I want to use structs for the (very simple) model of my app. However NSKeyedArchiver only accepts objects (extending NSObjects ). Is there any good way to save a struct to a file? 回答1: A very simple approach I used sometimes. The quantity of code you need to write is no more then in the class/NSCoding scenario. First of all import the great SwiftyJSON lib. Let's start with a simple struct struct Starship { let name: String let warpSpeed: Bool let captain: String? init(name: String, warpSpeed:

Ignore Non Serialized property in BinaryFormatter Serialization

眉间皱痕 提交于 2020-01-01 05:39:26
问题 I have a class called User and it is [Serializable] and inherited from base class IdentityUser an Entity Framework class and Non Serializable. I have a property in Booking class with type User and Booking class is Serializable I am trying to serialize the booking object using BinaryFormatter but I can't because of IdentityUser class and I get this error : 'Type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUser' in Assembly 'Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0,

Erlang's term_to_binary in Haskell?

好久不见. 提交于 2020-01-01 05:37:06
问题 Is there a no-fuss serialization method for Haskell, similar to Erlang's term_to_binary/binary_to_term calls? Data.Binary seems unnecessarily complicated and raw. See this example where you are basically manually encoding terms to integers. 回答1: Use Data.Binary, and one of the deriving scripts that come with the package. It's very simple to derive Binary instances, via the 'derive' or 'deriveM' functions provided in the tools set of Data.Binay. derive :: (Data a) => a -> String For any 'a' in

How do you serialize Android Intents?

只谈情不闲聊 提交于 2020-01-01 05:26:07
问题 Android Intents have a convenient toURI() method which the API docs seem to indicate is a way to serialize an Intent to a URI, and then later parse it back into an Intent. Unfortunately, in testing this functionality I found that it does not serialize all extras, just the primitive types (boolean, int, long, float, String). If an intent specifies any Parcelable or array extras then those will get lost. Where (if anywhere) is this limitation documented? Is there some obvious reason for this

How to encrypt and save a binary stream after serialization and read it back?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 05:24:10
问题 I am having some problems in using CryptoStream when I want to encrypt a binary stream after binary serialization and save it to a file. I am getting the following exception System.ArgumentException : Stream was not readable. Can anybody please show me how to encrypt a binary stream and save it to a file and deserialize it back correctly? The code is as follows: class Program { public static void Main(string[] args) { var b = new B {Name = "BB"}; WriteFile<B>(@"C:\test.bin", b, true); var bb

Are ViewScoped beans serialized to the page when client state saving is turned on?

六月ゝ 毕业季﹏ 提交于 2020-01-01 05:04:31
问题 We have client state saving turned on and use ViewScoped backing beans. When client state saving is turned on and we are using a ViewScoped bean, is the ViewScoped bean serialzied to the page or is it say, stored in session with a token/key that is serialized to the page (so that the page can recall the bean from session if the page is posted-back to itself) A concern here might be that, if it is serialized, then we might want to then worry about not storing large instance variables on the

serialize in .NET, deserialize in C++

依然范特西╮ 提交于 2020-01-01 04:29:10
问题 I have a .NET application which serializes an object in binary format. this object is a struct consisting of a few fields. I must deserialize and use this object in a C++ application. I have no idea if there are any serialization libraries for C++, a google search hasn't turned up much. What is the quickest way to accomplish this? Thanks in advance. Roey. Update : I have serialized using Protobuf-net , in my .NET application, with relative ease. I also get the .proto file that protobuf-net

How can I serialize dynamic object to JSON in C# MVC Controller action?

耗尽温柔 提交于 2020-01-01 04:26:05
问题 I want to serialize dynamic object to JSON. I tried using ExpandoObject, but the result is not what I need: public JsonResult Edit() { dynamic o = new ExpandoObject(); ((IDictionary<string,Object>)o)["abc"] = "ABC"; //or o.abc = "ABC"; return Json(o); } I want JSON to look like: {"abc": "ABC"} but instead it looks like [{"Key":"abc","Value":"ABC"}] Obviously ExpandoObject will not do, but can I inherit from DynamicObject and somehow override its methods to achieve JSON format I want? 回答1: I

Does Eclipse have an editor/viewer for java serialized files?

社会主义新天地 提交于 2020-01-01 04:19:10
问题 I'm serializing my objects with ObjectOutputStream(FileOutputStream(File)) and deserializing them with the analogous InputStreams . Is there a way to look inside of these serialized files (in eclipse preferably), so I can check, if all necessary attributes were written? edit: google search was negative 回答1: Write some tests (using Eclipse's built-in JUnit support). The only way to "look inside" these files is to use ObjectInputStream(FileInputStream(File)) , unless you're a bytecode guru and