serialization

serialize object for unit testing

喜欢而已 提交于 2019-12-24 03:43:13
问题 Assuming in a unit test I need to have an object all of 50 fields of which are set up with some values. I don't want to manually set up all this fields, as it takes time and annoying... Somehow I need to get an instance where all the fields are initialized by some not-null values. and I had an idea - what if I will debug some code, at some point i will get a working instance of this object with some data set up - and I just will serialize it to the disk. Then I will put this file to test

DjangoRestFramework - correct way to add “required = false” to a ModelSerializer field?

丶灬走出姿态 提交于 2019-12-24 03:43:00
问题 This is my serializer: class PostSerializer(serializers.ModelSerializer): class Meta: model = Post fields = ('user', 'post', 'reblog',) def create(self, validated_data): post = Post( user = validated_data['user'], post = validated_data['post'], ) post.save() # manually create a list of "reblog" users post.reblog.add(validated_data['user']) return post and this is my model: class Post(models.Model): user = models.ForeignKey(User) post = models.CharField(max_length=400) reblog = models

Why does boost::serialize not work despite everything seeming right? (“unregistered class”)

三世轮回 提交于 2019-12-24 03:35:23
问题 I am wondering about this. I have a C++ program with a number of data structs which derive from a common root and I need to serialize them using Boost. Each one has an inline member function to accept a visitor (so I can visit the structure without a "switch" statement). The objects look like this: In the .h file: // Graphic component. struct GraphicComponent : public Component { ... data members ... void accept(ComponentVisitor &vis) { vis.visitGraphicComponent(*this); } private: //

Object XML mapping in Android

寵の児 提交于 2019-12-24 03:29:31
问题 I am developing a client-server Model-based application in which client is in Android and server in PHP. I want to transfer product information for example Name,Price,Description, from client to server. I have read that through marshaling/unmarshaling or serialization it can be achieved but all tutorials and example are in Java. But I need in Android. Please guide me to implement in Android. Or there is any other way to implement? Any example will b appreciated. Thanks. 回答1: Have a look on

rails: editing serialized data in form

匆匆过客 提交于 2019-12-24 03:22:45
问题 I have a model that has one param that is a serialized Hash. I want to be able to edit the hash in a form using built in rails features. It is almost working. If you fill in the form and submit it, the params are correctly serialized and in the controller the model is built with the expected values. Where it falls apart is when I want the form to display an existing model: none of the values are displayed in the form fields. My model looks like: class Search < ActiveRecord::Base serialize

Formatting JSON using the RESTSerializer in the latest Ember Data version

爱⌒轻易说出口 提交于 2019-12-24 03:20:45
问题 I'm struggling to 'munge' my JSON into the correct format. To illustrate i've made a quick, JSfiddle. http://jsfiddle.net/chrismasters/NQKvy/638/ The format the server returns the data has a couple of differences to the preferred format recommended by Ember Data now. Here is the raw JSON output { "video": { "uuid": "8a660002-03c6-4b8e-bd8b-4ce28fa0dacd", "state": "pending", "theme": "basic", "resolution": "nHD", "title": "Test title", "track": { "uuid": "376fc3bb-d703-49e7-9d92-bce7f6bf8b56",

Generate c# object code and assign values to its properties from an xml document

不羁岁月 提交于 2019-12-24 03:06:21
问题 We have a xml file generated from a schema and these are shared with us, we need to generate c# code for from the xml file and set its properties. I can create a parser to do this, but was checking if there are any OOB solutions. for example <Customer> <fname>tom</fname> <lname>jerry</lname> </Customer> to Customer cust=new Customer(); fname="tom"; lname="jerry"; 回答1: I'd recommend to use Xslt to create your desired code output. This generic stylesheet will use the root node name as your

Can't get C++ Boost Pointer Serialization to work

青春壹個敷衍的年華 提交于 2019-12-24 02:38:09
问题 This question is not the same as the one listed as duplicate: Boost c++ serializing a char * I am not using shared_ptr, and I have full access to the internals of my classes. The closest response I could find was in Store a vector of pointers to custom objects to file which I found by searching for the compiler error. However, the answer given there was not clear, at least not to me. It points back to the boost docs, which indicate that the simple code I have listed here should work. After

protobuf-net UseImplicitZeroDefaults and Enum defaults

南楼画角 提交于 2019-12-24 02:28:11
问题 We're trying to use protobuf-net but having trouble understanding UseImplicitZeroDefaults which we now disable in a custom RuntimeTypeModel. We initially used the default RuntimeTypeModel but noticed boolean properties were not being cloned even though a DefaultValue was being specified, i.e. DefaultValue=true but when set to false the cloned property would always be true. We resolved this by creating a custom RuntimeTypeModel which has allowed us to set UseImplicitZeroDefaults to false. But

protobuf-net UseImplicitZeroDefaults and Enum defaults

自作多情 提交于 2019-12-24 02:28:06
问题 We're trying to use protobuf-net but having trouble understanding UseImplicitZeroDefaults which we now disable in a custom RuntimeTypeModel. We initially used the default RuntimeTypeModel but noticed boolean properties were not being cloned even though a DefaultValue was being specified, i.e. DefaultValue=true but when set to false the cloned property would always be true. We resolved this by creating a custom RuntimeTypeModel which has allowed us to set UseImplicitZeroDefaults to false. But