serialization

Serialize DetachedCriteria with nHibernate

狂风中的少年 提交于 2019-12-22 11:29:15
问题 I am trying to serialize a DetachedCriteria so I can save it in a database and reuse the same criteria at a later date. When I run the code below I get "NHibernate.Criterion.DetachedCriteria cannot be serialized because it does not have a parameterless constructor". DetachedCriteria criteria1 = DetachedCriteria.For<SecurityObjectDTO>("so") .Add(Expression.Eq("ObjectCode", "1234")); XmlSerializer s = new XmlSerializer(typeof(DetachedCriteria)); TextWriter writer = new StringWriter(); s

Can a byte[] buffer for a MemoryStream have variable size?

a 夏天 提交于 2019-12-22 11:21:37
问题 I'm serializing an object to a byte[] using MemoryStream : byte[] serialized = new byte[1000]; using (MemoryStream stream = new MemoryStream(serialized)) using (TextWriter textWriter = new StreamWriter(stream)) serializer.Serialize(textWriter, stuffToSerialize); is there any way I can set 'serialized' to grow according to the size of the stuffToSerialize ? 回答1: The parameterless constructor new MemoryStream() uses one. Then serialise into it, and then when you need the byte[] call ToArray()

Jackson xml empty element serialization

拈花ヽ惹草 提交于 2019-12-22 11:03:53
问题 I'm having a hard time with this one. Jackson 2.2 XML serializer seems to serialize empty object fields this way: <field/> How can I force it to serialize such empty field like this: <field></field> Thank you very much for your time and answers. 回答1: Please, see this question: How do you override the null serializer in Jackson 2.0?. For XmlMapper it could look like below. Create NullSerializer : class NullSerializer extends JsonSerializer<Object> { @Override public void serialize(Object value

How to debug serialization error in tombstoned WP7 app

﹥>﹥吖頭↗ 提交于 2019-12-22 10:49:08
问题 I am handling the current state of my WP7 app in the OnNavigatedFrom and To events so that if the app is tombstoned OR they navigate to a different page it saves the state to the inbuilt PhoneApplicationService state. I have a simple ViewModel which I dump to the state to make life easier. When navigate to a different page within my app, the state is stored fine and restores fine (ie. I assume it is serializing at this point). However, when I tombstone the app (i.e. Start button) I am getting

Boost serialization does not work between 32bit and 64bit machine. Any other serialization / compression library?

我的未来我决定 提交于 2019-12-22 10:46:50
问题 I am trying to use the boost library to serialize on 64bit machine and de-serialize on 32bit machine. However, it seems it does not work. (I use 1.57.0). If I run the following code boost::asio::streambuf buf; std::ostream os(&buf); boost::archive::binary_oarchive oa(os); printf("Buffer size %d\n",(int)buf.size()); The output of 32bit machine is 37 and the output of 64bit machine is 41 . Is there any other good serialize library I can Use? How about cereal ? It's great if the library can do

How to write a catch-all (de)serializer for Jackson

和自甴很熟 提交于 2019-12-22 10:43:35
问题 Writing a custom serializer is pretty easy when you know the type in advance. For eg. MyType one can write a MyTypeSerializer extends StdSerializer<MyType> . See http://wiki.fasterxml.com/JacksonHowToCustomSerializers But, let's say that: I have objects of several types (interfaces) going through Jackson serialization. I don't know the type of theses objets in advance. I can't add annotations on theses types. all theses objets can be cast to a common type I know so that I can get its state

Serializing/Deserializing Protocol Buffers

半城伤御伤魂 提交于 2019-12-22 10:36:00
问题 I am currently working with Protocol Buffers (version 3 C#). I am sending messages back and forth to different services. and currently trying to save some data stored in certain messages to a database (could be of any kind really). The problem being that byte[] is created as the type ByteString and List< T> is created as RepeatedField< T> . Now the issue I have with these are that I haven't managed to serialize or deserialize them 100% successfully. Basic types works like a charm, but

PHP Accessing a child's private properties in parent

末鹿安然 提交于 2019-12-22 10:27:22
问题 I have a parent object that I use for general CRUD in my applications - it has basic save & retrieve methods so I can don't have to reinclude them them in all my objects. Most of my child objects extend this base object. This has worked fine, but I'm finding a problem with retrieving a serialized child object. I use a "retrieve" method in the parent object that creates an instance of the child, then populates itself from the properties of the unserialized child - this means is can "self

Unity Deserializing from server [duplicate]

不想你离开。 提交于 2019-12-22 10:27:12
问题 This question already has answers here : Serialize and Deserialize Json and Json Array in Unity (7 answers) Closed 2 years ago . I have been trying for a couple hours to deserialize info from my server for our high score system. However I am getting an error: ArgumentException: JSON must represent an object type. This is how I am deserializing ( scores is of type Scores): public void Deserialize() { Debug.Log("From Server is ::::: -----> " + FromServer); scores = JsonUtility.FromJson<Scores>

How to update WPF UI at deserialization of “settings” object

久未见 提交于 2019-12-22 10:15:47
问题 My goal is to do this: User selects settings file, settings are read and the UI is updated correspondingly. Saving should also be possible obviously. My program is currently not WPF/XAML and doing this now would mean a lot of repetition and added work when new settings are required. So someone told me WPF/XAML was the way to go, I looked into it and liked it but I'm still not sure how to do what I want. The advantage of WPF/XAML is of course data bindings, but if I want to read a whole