serialization

Is there a built in way in .Net AJAX to manually serialize an object to a JSON string?

删除回忆录丶 提交于 2019-12-20 12:30:21
问题 I've found ScriptingJsonSerializationSection but I'm not sure how to use it. I could write a function to convert the object to a JSON string manually, but since .Net can do it on the fly with the <System.Web.Services.WebMethod()> and <System.Web.Script.Services.ScriptMethod()> attributes so there must be a built-in way that I'm missing. PS: using Asp.Net 2.0 and VB.Net - I put this in the tags but I think people missed it. 回答1: This should do the trick Dim jsonSerialiser As New System.Web

Serialization and object versioning in C#

让人想犯罪 __ 提交于 2019-12-20 12:22:47
问题 If I want to serialize an object I have to use [Serializable] attribute and all member variables will be written to the file. What I don't know how to do versioning e.g. if I add a new member variable (rename a variable or just remove a variable) and then I open (deserialize) the file how can I determine the object/file version so I can correctly set the new member or take some kind of migration? How can I determine that the variable was initialized during the load or not (ignored by

Serializing Java objects to Cassandra 1.2 via ByteBuffer & CQL 3

家住魔仙堡 提交于 2019-12-20 11:55:37
问题 I've cobbled together the below code that doesn't do anything complex -- just creates a byte[] variable, writes it into a blob field in Cassandra (v1.2, via the new Datastax CQL library), then reads it back out again. When I put it in it's 3 elements long, and when I read it back it's 84 elements long...! This means the thing I'm actually trying to do (serialize Java objects) fails with an org.apache.commons.lang.SerializationException: java.io.StreamCorruptedException: invalid stream header:

Why does serialize() have the same effect as serializeArray() when setting post data for jQuery.ajax()?

旧城冷巷雨未停 提交于 2019-12-20 11:51:04
问题 i have this jQuery-AJAX code below and a form: <script type="text/javascript"> $(document).ready(function () { $('form').submit(function () { form_data = $(this).serializeArray(); $.ajax({ url: "/frontend_dev.php/coche1/update/id/1", type: "POST", data: form_data }); }); return false; }); </script> As you can see I'm using serializeArray() but when i use serialize() it also works the same.. Why in both cases works the same? What of them should i use? Im using symfony as php framework. I can

Why does serialize() have the same effect as serializeArray() when setting post data for jQuery.ajax()?

烂漫一生 提交于 2019-12-20 11:49:08
问题 i have this jQuery-AJAX code below and a form: <script type="text/javascript"> $(document).ready(function () { $('form').submit(function () { form_data = $(this).serializeArray(); $.ajax({ url: "/frontend_dev.php/coche1/update/id/1", type: "POST", data: form_data }); }); return false; }); </script> As you can see I'm using serializeArray() but when i use serialize() it also works the same.. Why in both cases works the same? What of them should i use? Im using symfony as php framework. I can

Add a count field to a django rest framework serializer

我们两清 提交于 2019-12-20 11:22:47
问题 I am serializing the built-in django Group model and would like to add a field to the serializer that counts the number of users in the group. I am currently using the following serializer: class GroupSerializer(serializers.ModelSerializer): class Meta: model = Group fields = ('id', 'name', 'user_set') This returns the group ID and name and an array of users (user IDs) in the group: { "id": 3, "name": "Test1", "user_set": [ 9 ] } What I would like instead as output is something like: { "id":

Does protobuf-net have built-in compression for serialization?

扶醉桌前 提交于 2019-12-20 11:07:49
问题 I was doing some comparison between BinaryFormatter and protobuf-net serializer and was quite pleased with what I found, but what was strange is that protobuf-net managed to serialize the objects into a smaller byte array than what I would get if I just wrote the value of every property into an array of bytes without any metadata. I know protobuf-net supports string interning if you set AsReference to true , but I'm not doing that in this case, so does protobuf-net provide some compression by

AttributeError while using Django Rest Framework with serializers

百般思念 提交于 2019-12-20 11:03:14
问题 I am following a tutorial located here that uses Django Rest Framework, and I keep getting a weird error about a field. I have the following model in my models.py from django.db import models class Task(models.Model): completed = models.BooleanField(default=False) title = models.CharField(max_length=100) description = models.TextField() Then my serializer in serializers.py from rest_framework import serializers from task.models import Task class TaskSerializer(serializers.ModelSerializer):

Should I use Pickle or cPickle? [closed]

时间秒杀一切 提交于 2019-12-20 10:58:39
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . Python has both the pickle and cPickle modules for serialization. cPickle has an obvious advantage over pickle : speed. What, if any, advantage does pickle have over cPickle ? 回答1: The pickle module implements an algorithm for turning an arbitrary Python object into a series

Sending an object over the Internet

天涯浪子 提交于 2019-12-20 10:45:14
问题 I define a class, and then I instate an object of that class type. I want to send this object to another Java application running on a different computer transparently. What is the best technology to accomplish this? 回答1: you can create object streams using the java API and send any serializable object. but you'll have to mind that these go unencrypted through the network: on the sender's side: CustomObject objectToSend=new CustomObject(); Socket s = new Socket("yourhostname", 1234);