serialization

Level-field validation in django rest framework 3.1 - access to the old value

这一生的挚爱 提交于 2019-12-24 23:30:29
问题 Before updating object the title field is validated. How to access data of serialized object in order to compare value with older value of this object? from rest_framework import serializers class BlogPostSerializer(serializers.Serializer): title = serializers.CharField(max_length=100) content = serializers.CharField() def validate_title(self, value): """ Check that the blog post is about Django. """ if 'django' not in value.lower(): raise serializers.ValidationError("Blog post is not about

Serializing / Deserializing the derived class

时间秒杀一切 提交于 2019-12-24 23:24:37
问题 I have a base class and another derived from it. Let's assume, the base class has 20 members and derived has 5 members. Only the derived class is serializable. After I instantiate, the derived class's object has all 25 members. Now how can I only serialize the 5 members of derived class? When I use "this" to serizalize or deserialize, the entire class (all 25 members) is serialized and then deserialized. Here is a code snippet (not complete): // Base class definition. public abstract class

Deserialize certain JSON properties into subclass

雨燕双飞 提交于 2019-12-24 23:20:06
问题 public class ApiResponse<T> : IApiResponse<T> { public long QuotaRemaining { get; set; } public long QuotaMax { get; set; } public int Backoff { get; set; } public bool HasMore { get; set; } public long Total { get; set; } public string Type { get; set; } //public long ErrorId { get; set; } //public string ErrorMessage { get; set; } //public string ErrorName { get; set; } public IList<T> Items { get; set; } public ApiError Error { get; set; } } public class ApiError { [JsonProperty("error_id"

Control XML serialization of Dictionary<K, T>

北战南征 提交于 2019-12-24 23:15:38
问题 I'm investigating about XML serialization, and since I use lot of dictionary, I would like to serialize them as well. I found the following solution for that (I'm quite proud of it! :) ). [XmlInclude(typeof(Foo))] public class XmlDictionary<TKey, TValue> { /// <summary> /// Key/value pair. /// </summary> public struct DictionaryItem { /// <summary> /// Dictionary item key. /// </summary> public TKey Key; /// <summary> /// Dictionary item value. /// </summary> public TValue Value; } ///

What Class for Serializable Multidimensional Arrays?

时间秒杀一切 提交于 2019-12-24 21:56:46
问题 EDIT: See Below I have a web service which uses a class of functions in order to return data used in various business processes (via InfoPath). One of the functions takes a given SQLCommand object and executes it into a SQLDataReader. Now depending on the SQL command text used this may return one or many rows of one or many columns. So what is the best class for this function to return bearing in mind it needs to be serialized by the web service. My existing code is: Dim array As New

How can a Delphi TForm / TPersistent object calculate its own construction and deserialization time?

喜你入骨 提交于 2019-12-24 21:40:22
问题 For performance tests I need a way to measure the time needed for a form to load its definition from the DFM. All existing forms inherit a custom form class. To capture the current time, this base class needs overriden methods as "extension points": start of the deserialization process after the deserialization (can be implemented by overriding the Loaded procedure) the moment just before the execution of the OnFormCreate event So the log for TMyForm.Create(nil) could look like: - 00.000

Deserialize multiple json into object c#

纵饮孤独 提交于 2019-12-24 21:09:02
问题 I'm trying to deserialize a json string from a API call with multiple objects but without much success. JSON: @{ "purchaseOrders": [ { "supplierId": "500", "currencyCode": "EUR", "companyId": "LALA", "companyName": "LALA", "purchaseOrderLines": [ { "lineNumber": "10", "itemNumber": "255", "itemDescription": "TestItem2", "unitPrice": 24.64, "quantity": 2, "isServiceBased": false, "taxIndicator1": "LAAA5", "taxIndicator2": "4", "unit": "-", "deliveryLines": [], "supplierItems": [], "isActive":

HashBiMap SerializationException or how to serialize classes where IsSerializable is not applicable?

狂风中的少年 提交于 2019-12-24 20:53:48
问题 Problem seems to be that not all Guava classes are serializable out-of-the-box. I found a quite good solution to this and like to share it. (in this case for HashBiMap). (Maybe some Guava developers may apply this one day to ideally all of the classes) If you copy the below class (and maybe adjust it to your to-be-serializable class) you will have further investigation details inside the Javadoc comment already. package com.google.common.collect; import java.util.LinkedHashMap; import java

Serialize a group of integers using cython

假如想象 提交于 2019-12-24 20:50:25
问题 I saw this sample code from the Pyrobuf page for serializing an integer ~3 times faster than via struct.pack : def ser2(): cdef int x = 42 return (<char *>&x)[:sizeof(int)] I was wondering how this could be done for a group of integers. I saw cython has int[:] and array.array types, but I still don't understand how do I take a list of integers for example, and get the same (but faster) result as via struct.pack('i', *num_list) . map() didn't seem work faster for me, and I'm wondering how this

Check serialization method

你。 提交于 2019-12-24 20:45:56
问题 I am running a program on Apache Flink. I got this error: Caused by: java.io.IOException: Thread 'SortMerger Reading Thread' terminated due to an exception: Serializer consumed more bytes than the record had. This indicates broken serialization. If you are using custom serialization types (Value or Writable), check their serialization methods. If you are using a Kryo-serialized type, check the corresponding Kryo serializer. How can I check the serialization method of an object in Scala/Java?