serialization

partial or full object serialization

孤者浪人 提交于 2019-12-25 06:04:30
问题 Consider the following Student defintion: public class Student { public Guid Id {get; set;} public String FirstName {get; set;} public String LastName { get; set; } } Using C# serialization attributes, how can you apply two different serialization configurations? When the object is passed to the DataContractSerializer , the user could specify "idOnly" (partial) or "full" serialization. I have a two runtime use cases: Only serialize the Guid Full serialization of the Object. 回答1: I don't know

How to create a clone of an entity collection without preserving relationship in doctrine?

拥有回忆 提交于 2019-12-25 05:34:19
问题 I've been trying to figure out how to get this to work for along time but without any luck. Due to a complex logic in an app I'm working on, I need to create an isolated clone of a entity collection without preserving what so ever relation to the database. Whatever changes I do on the cloned collection should not be tracked by Doctrine at all and should be treated as if it doesn't exist at all. Here's an example code: /* * @ORM\Entity() */ class Person { /** * @var integer * * @ORM\Id * @ORM

Gson : Is there a way to preserve type information if serialization/deserialization target is an Object

为君一笑 提交于 2019-12-25 05:32:40
问题 I have the following code import com.google.gson.Gson; /** * * @author yccheok */ public class JavaApplication18 { public static class Holder { public Object value; } /** * @param args the command line arguments */ public static void main(String[] args) { Gson gson = new Gson(); Integer i = new Integer(123); Holder holder = new Holder(); holder.value = i; String json = gson.toJson(holder); System.out.println(json); Holder newHolder = gson.fromJson(json, Holder.class); System.out.println

Why does a UserControl cause a Serialization error?

爱⌒轻易说出口 提交于 2019-12-25 05:24:06
问题 I have the following ComboBox in my MainWindow.xaml: <ComboBox ItemsSource="{Binding ComboItemsProperty}" /> In MainWindow.xaml.cs: ObservableCollection<string> ComboItemsField = new ObservableCollection<string>(); public ObservableCollection<string> ComboItemsProperty { get { return ComboItemsField; } set { ComboItemsField = value; } } This works perfectly! I can add items to the Property and successfully Serialize the ComboBox Element. My question is, why is it when I have this EXACT code

Deserialize a class with interface

不羁岁月 提交于 2019-12-25 05:23:12
问题 I have a class which contain an interface member variable.How can i deserialize this class interface ISensor { } [Serializable] class Sensor: ISensor { } [Serializable] class Root { [XmlElement("Sensor")] public List<ISensor> SensorList{ get; set; } } My XML will be like this <?xml version="1.0" encoding="us-ascii"?> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Sensor > <SensorName>Name1</SensorName> <SensorValue>0.0</SensorValue>

Deserialize Xml Using Same Object With Different Element Name

三世轮回 提交于 2019-12-25 04:52:08
问题 I have an EventType and Events classes to serialize/deserialize. In Xml for Events there is a XmlElement named "type". <?xml version="1.0" encoding="UTF-8"?> <events type="array"> <event> <where /> <project-users-can-edit type="boolean">false</project-users-can-edit> <description /> <attending-user-ids type="integer">164316</attending-user-ids> <notify-user-names>Levent A.</notify-user-names> <attending-user-names>Levent A.</attending-user-names> <status>active</status> <owner> <first-name

Serialize a generic collection specifying element names for items in the collection

♀尐吖头ヾ 提交于 2019-12-25 04:49:07
问题 I have a simple class derived from a generic list of string as follows: [Serializable] [System.Xml.Serialization.XmlRoot("TestItems")] public class TemplateRoleCollection : List<string> { } when I serialize this, I get the following XML: <TestItems> <string>cat</string> <string>dog</string> <string>wolf</string> </TestItems> Is there any way to override the xml element name which is used for serializing items in the collection? I would like the following xml to be produced: <TestItems>

Ember 2.7, Rails 5, JSONAPI, Active Model Serializers - counting the number of records in a hasMany relationship

感情迁移 提交于 2019-12-25 04:48:12
问题 This idea started with this question. 2 models: class Trail < ApplicationRecord has_many :notes, dependent: :destroy end class Note < ApplicationRecord belongs_to :trail end 2 serializers: class NotesSerializer < ActiveModel::Serializer attributes :id, :note_body belongs_to :trail end class TrailSerializer < ActiveModel::Serializer attributes :id, :name, :notes_count has_many :notes def notes_count object.notes.size end end When calling the route trails/index, this will fire for every Trail,

convert array to json and receive in ashx handler

柔情痞子 提交于 2019-12-25 04:42:49
问题 I've been trying a lot of possible solutions and none of them worked, i have something like this, but i don know if the json structure is correct, or i'am not sending it correctly to the server side, i'd like to know where is the source of the problem. This is the error: No parameterless constructor defined for type of 'System.String[]'. Client-Side function upload() { var title = []; var files = $('#myfile').prop("files"); var names = $.map(files, function (val) { return val.name; }); for

How to get a field of a foreign key Model appear in a Django-Serializer?

只愿长相守 提交于 2019-12-25 04:26:35
问题 I am building a Django application that exposes a REST API by which users can query 2 of my application's models. I'm following the instructions here. My two models are: The Django User model from django.contrib.auth The model shown below. class Profile(models.Model): user = models.OneToOneField(User) My Serialiazers are as follows: class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User fields = ('url', 'username', 'email', ) class ProfileSerializer(serializers