serialization

Django Rest Framework ModelSerializer Set attribute on create

て烟熏妆下的殇ゞ 提交于 2019-12-21 20:36:13
问题 When creating an object initially I use the currently logged-in user to assign the model field 'owner'. The model: class Account(models.Model): id = models.AutoField(primary_key=True) owner = models.ForeignKey(User) name = models.CharField(max_length=32, unique=True) description = models.CharField(max_length=250, blank=True) Serializer to set owner: class AccountSerializer(serializers.ModelSerializer): class Meta: model = models.Account fields = ('name', 'description') def restore_object(self

C# serialize large array to disk

孤街浪徒 提交于 2019-12-21 20:35:07
问题 I have a very large graph stored in a single dimensional array (about 1.1 GB) which I am able to store in memory on my machine which is running Windows XP with 2GB of ram and 2GB of virtual memory. I am able to generate the entire data set in memory, however when I try to serialize it to disk using the BinaryFormatter , the file size gets to about 50MB and then gives me an out of memory exception. The code I am using to write this is the same I use amongst all of my smaller problems:

c# serialization - complex type containing simple content with attributes

倾然丶 夕夏残阳落幕 提交于 2019-12-21 20:34:12
问题 I have an existing solution that has used svcutil to create a set of classes based on an XSD schema. I am now having to make edits to that schema and I have run into a bit of a stumbling block. The schema is going to be extended with types like this: <xsd:complexType name="Awkward"> <xsd:sequence> <xsd:element name="awkward1" type="tt:AwkwardChild" nillable="true"> </xsd:element> <xsd:element name="awkward2" type="tt:AwkwardChild" nillable="true"> </xsd:element> </xsd:sequence> </xsd

Deserialize elements to properties based on attribute

大兔子大兔子 提交于 2019-12-21 20:28:09
问题 I am looking to see if there is a simple way to deserialize an XML file filled with elements back to a class of properties, specifically on the elements attribute 'name' as the property to attach to. For example, I have an XML file format given as: <?xml version="1.0" encoding="utf-8"?> <settings> <setting name="number_val_one">1</setting> <setting name="string_val_one">test</setting> <setting name="number_val_two">42</setting> <setting name="string_val_two">hello world</setting> </settings>

belongsTo promise is unsettled when serializing a modified record

北慕城南 提交于 2019-12-21 20:16:10
问题 Okay the obligatory information: DEBUG: ------------------------------- DEBUG: Ember : 1.3.1 DEBUG: Ember Data : 1.0.0-beta.7.f87cba88 DEBUG: Handlebars : 1.0.0 DEBUG: jQuery : 1.10.2 DEBUG: ------------------------------- Here are the relevant models: App.Destination = DS.Model.extend({ label: DS.attr('string'), destinationMatchRules: DS.hasMany('destinationMatchRule', { async: true }), chargeRules: DS.hasMany('chargeRule', { async: true }), }); App.ChargeRule = DS.Model.extend({ startDate:

SOAP generic type serialization

给你一囗甜甜゛ 提交于 2019-12-21 20:00:10
问题 We have created a class to wrap the payload of web service response with common information as follows. public class ItemResponse<T> : Response { /// <summary> /// constructor to set private properties Item and Status /// </summary> /// <param name="item"></param> /// <param name="status"></param> public ItemResponse(T item, ResponseStatusEnum status) : base(status) { _item = item; } public ItemResponse() { } public ItemResponse(ResponseStatusEnum status, System.Collections.Generic.List

Hadoop: Easy way to have object as output value without Writable interface

本小妞迷上赌 提交于 2019-12-21 17:39:33
问题 I am trying to exploit hadoop to train multiple models . My data are small enough to fit in memory so i want to have one model trained in every map task. My problem is that when i have finished training my model, i need to send it to the reducer. I am using Weka to train the model. I don't want to start looking how to implement the Writable interface in Weka classes, because it needs a lot of effort. I am looking for a simple way to do this. The Classifier class in Weka implements the

C# Can't catch SerializationException

你离开我真会死。 提交于 2019-12-21 17:32:23
问题 I'm having an issue in my program in the part that I'm loading a serialized file. I want to fail nicely if the file can't be deserialzed, but for some reason, my program will break rather than go into the catch clause. Here's my code using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open)) { try { BinaryFormatter bf = new BinaryFormatter(); document = (Document)bf.Deserialize(fs); } catch (SerializationException se) { MessageBox.Show("Error opening this file due to

Serialize & Deserialize bean to json with Groovy

自闭症网瘾萝莉.ら 提交于 2019-12-21 17:30:54
问题 I've read this news about json with groovy http://www.infoq.com/news/2014/04/groovy-2.3-json. So I tried to native methods to (de)serialization of groovy bean containing dates. But I have issues whent using JsonOutput.toJson(object) with JsonObject.fromObject() with java.util.Date String jsonDat a= groovy.json.JsonOutput.toJson(contact) Contact reloadContact = new Contact(net.sf.json.JSONObject.fromObject(jsonData)) What is the right way to to this with native methods in groovy 2.3+ ?

JSON Serialize / Deserialize generic type with google-gson

泄露秘密 提交于 2019-12-21 17:23:42
问题 Well, I have to confess I'm not good at generic type in Java I've written a JSON serialize/deserialize class in C# using JavaScriptSerializer private static JavaScriptSerializer js = new JavaScriptSerializer(); public static T LoadFromJSONString<T>(string strRequest) { return js.Deserialize<T>(strRequest); } public static string DumpToJSONString<T>(T rq) { return js.Serialize(rq); } It works well in C#. Now I'm trying to convert, or atleast, write another JSON serialize/deserialize class in