serialization

Exclude null objects from JSON array with Gson

坚强是说给别人听的谎言 提交于 2019-12-23 03:59:10
问题 I'm using Gson to parse my REST API calls to Java objects. I want to filter out null objects in an array, e.g. { list: [ {"key":"value1"}, null, {"key":"value2"} ] } should result in a List<SomeObject> with 2 items. How can you do this with Gson? 回答1: Answer: The Custom Serializer You can add a custom serializer for List.class which would look like: package com.dominikangerer.q27637811; import java.lang.reflect.Type; import java.util.Collections; import java.util.List; import com.google.gson

Data contract serialization with complex types

喜欢而已 提交于 2019-12-23 03:50:24
问题 I am using Data Contract serialization to serialize the following classes in XML: [DataContract] public partial class Foo { [DataMember] public string MyString { get; set; } [DataMember] public int MyInt { get; set; } [DataMember] public Bar MyBar { get; set; } } [DataContract] public class Bar { public int BarId { get; set; } [DataMember] public string BarField { get; set; } } When I serialize it it generates XML like this: <Foo> <MyString>My text</MyString> <MyInt>2</MyInt> <MyBar>

MFC serialization

大兔子大兔子 提交于 2019-12-23 03:49:09
问题 i have to serialize a CList of base and derived classes. How can i do that. typedef CList<Student*, Student*> StVec; class Student : public CObject { public: DECLARE_SERIAL(Student); Student(); Student(Student& s); Student(CString _name, CString _last, int _age); virtual ~Student(void); virtual void cin(); virtual void cout(); virtual void Serialize(CArchive& ar); static Student* FromInput(); inline const CString GetName(){return name;} inline const CString GetLastName(){return last_name;}

Xmlserializer to C# object, store original XML element

感情迁移 提交于 2019-12-23 03:38:17
问题 Is it possible to store the original XML element in a C# class, for example? Original XML: <data someattributea="" someattributeb="" someattributec="" /> C# using System; using System.Xml.Serialization; using System.Collections.Generic; namespace Xml2CSharp { [XmlRoot(ElementName="data")] public class Data { [XmlAttribute(AttributeName="someattributea")] public string Someattributea { get; set; } [XmlAttribute(AttributeName="someattributeb")] public string Someattributeb { get; set; }

C# XML Serialization/DeSerialization [closed]

安稳与你 提交于 2019-12-23 03:17:06
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm having a look at XML Serialization and have serialized as such: public static string Serialize<T>(T data) { XmlSerializer xmlSerializer = new

Convert class to string to send via email

我们两清 提交于 2019-12-23 03:12:52
问题 I'm creating a form whose fields need to get sent via email. It's an internal project so timeline is tight and the email doesn't need to be pretty. Is there a quick and dirty way to serialize/format a class into a readable string similar to this: Field1Name: This is the value of field1 Field2Name: value of field 2 I could write up some reflection to do it without much issue, but I'm curious if there is something already built in to .NET that might do it for me. Like I said, I'm looking for

Serialize all id's in a div using jquery

↘锁芯ラ 提交于 2019-12-23 03:10:00
问题 I am trying to create a re-ordering of the page drag and drop feature on my CMS. As some of the pages have sub pages, we have a lot of lists nested within lists. An example of the code: $(document).ready(function(){ $(function() { $('#contentLeft ul').sortable({ update: function() { var order = $('#contentLeft ul').sortable('serialize'); alert(order); } }); }); }); <div id="contentLeft"> <ul id="sitemap"> <li id="page_1" class="page_container"> Test <ul> <li id="page_20">Nested one</li> <li

Deserializing JSON Object into C# list

流过昼夜 提交于 2019-12-23 03:04:39
问题 I have some JSON that I want to deserilize into a list<> object. I am using JsonConvert by Newtonsoft and I have setup my public classes to support the list. These are as follows. public class NewDocumentObject { public int ContractId { get; set; } public int FolderId { get; set; } public string CreatedAt { get; set; } public string CreatedBy { get; set; } public string TemplateReference { get; set; } public bool IsTest { get; set; } public bool IsExplicitName { get; set; } public object

How to get JSON ARRAY and JSON object response from retrofit response?

余生长醉 提交于 2019-12-23 02:45:33
问题 I have worked with file upload using retrofit. It works fine. But how do handle the retrofit success response. and How do i create serialization model class for below Json array and Json object. { "result": [{ "fileId": 869, "status": 1, "pcData": { "id": 652, "filename": "IMG_20161122_175344.jpg", "filepath": "uploads\/peoplecaddie\/files\/1743_1481109145_IMG_20161122_175344.jpg" } }] } Here is My call method Call<ServerResponse> call = service.upload("817b6ce98fd759e7f148b948246df6c1", map,

django: control json serialization

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 02:43:08
问题 Is there a way to control json serialization in django? Simple code below will return serialized object in json: co = Collection.objects.all() c = serializers.serialize('json',co) The json will look similar to this: [ { "pk": 1, "model": "picviewer.collection", "fields": { "urlName": "architecture", "name": "\u0413\u043e\u0440\u043e\u0434 \u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430", "sortOrder": 0 } }, { "pk": 2, "model": "picviewer.collection", "fields": {