serialization

Convert Record to Serialized Form Data for sending via HTTP

别来无恙 提交于 2019-12-28 03:11:04
问题 Is there a way to convert this Record TError = record code: Word; message: String; end; TState = record caption: String; address: Cardinal; counters: TArray<Word>; errors: TArray<TError>; end; to serialized Form Data string ( Content-Type: application/x-www-form-urlencoded ) like caption=Foo& address=175896& counters[]=2& counters[]=2& errors[0][code]=52& errors[0][message]=ERR_NOT_AVAILABLE for sending via HTTP? Maybe there is some function similar to JQuery.param()? 回答1: Ok, here is a

Serializing Map<Date, String> with Jackson

我的梦境 提交于 2019-12-28 02:44:09
问题 I want to serialize a Map with Jackson. The Date should be serialized as a timestamp, like all my other dates. The following code renders the keys in the form "Tue Mar 11 00:00:00 CET 1952" (which is Date.toString()) instead of the timestamp. Map<Date, String> myMap = new HashMap<Date, String>(); ... ObjectMapper.writeValue(myMap) I assume this is because of type erasure and jackson doesn't know at runtime that the key is a Date. But I didn't find a way to pass a TypeReference to any

JSON.NET as a WebAPI 2 OData serializer vs ODataMediaTypeFormatter

喜夏-厌秋 提交于 2019-12-27 14:57:59
问题 I'm trying to use JSON.NET as a default serializer in WebAPI 2 stack. I've implemented JsonMediaTypeFormatter, in which I've used JSON.NET serializer for serialize/deserialize data and created JsonContentNegotiator for using this media type formatter. All works fine except OData querying - if I add [Queryable] metadata ot action method, then response object doesn't contains any metadata information, only list of entities. Small example. My action method: [Queryable] public async Task

JSON.NET as a WebAPI 2 OData serializer vs ODataMediaTypeFormatter

最后都变了- 提交于 2019-12-27 14:56:26
问题 I'm trying to use JSON.NET as a default serializer in WebAPI 2 stack. I've implemented JsonMediaTypeFormatter, in which I've used JSON.NET serializer for serialize/deserialize data and created JsonContentNegotiator for using this media type formatter. All works fine except OData querying - if I add [Queryable] metadata ot action method, then response object doesn't contains any metadata information, only list of entities. Small example. My action method: [Queryable] public async Task

Gson Serialize field only if not null or not empty

时光总嘲笑我的痴心妄想 提交于 2019-12-27 14:33:13
问题 I have requirement where I need to convert java object to json. I am using Gson for that but i need the converter to only serialize the non null or not empty values. For example: //my java object looks like class TestObject{ String test1; String test2; OtherObject otherObject = new OtherObject(); } now my Gson instance to convert this object to json looks like Gson gson = new Gson(); TestObject obj = new TestObject(); obj.test1 = "test1"; obj.test2 = ""; String jsonStr = gson.toJson(obj);

XSLT: How to convert XML Node to String

江枫思渺然 提交于 2019-12-27 12:04:30
问题 <ROOT> <A> <B>TESTING</B> </A> </ROOT> XSL: <xsl:variable name="nodestring" select="//A"/> <xsl:value-of select="$nodestring"/> I am trying to convert XML nodeset to string using XSL. Any thoughts? 回答1: You need to serialize the nodes. The most simple for your example would be something like <xsl:template match="ROOT"> <xsl:variable name="nodestring"> <xsl:apply-templates select="//A" mode="serialize"/> </xsl:variable> <xsl:value-of select="$nodestring"/> </xsl:template> <xsl:template match="

Json.Net: Serialize/Deserialize property as a value, not as an object

瘦欲@ 提交于 2019-12-27 10:58:02
问题 How can I achieve the following JSON representation of Id class when used in another class? class Car { public StringId Id { get; set; } public string Name { get; set; } } class StringId { public string Value { get; set; } } // --------------------------------------------- // Desired representation { "Id": "someId", "Name": "Ford" } // Default (undesired) representation { "Id" : { "Value": "someId" }, "Name": "Ford" } 回答1: You could add a TypeConverter for StringId . Json.NET will pick up the

Mysql: get all distinct values from field serialized by PHP

时光毁灭记忆、已成空白 提交于 2019-12-25 23:07:31
问题 I have a movies table (has data from a legacy project) with the field genre which contains values serialized by PHP like: a:3:{i:0;s:9:"Animation";i:1;s:9:"Adventure";i:2;s:5:"Drama";} I'm working in a search page, & I need to find all unique genres of the current search result to be used as a filter in the page, as an example, if the search result was these 2 movies: The Dark Knight (action, crime, drama) Black Knight (fantasy, adventure, comedy) I want to know the combination of there

notserializableexception for an object whose class implements Serializable

淺唱寂寞╮ 提交于 2019-12-25 19:36:54
问题 I have this class public class wordObject implements java.io.Serializable { String wordName; int occCount; int count; HashMap<Integer, Double> lineDict; int[] mat; public wordObject(String name,int num) { wordName = name; occCount=1; count = num; lineDict=new HashMap<Integer,Double>(lineC); mat = new int[lineC]; } } But when I try to write an instance of the class to the disk using a piece of code as given below public static writeObj(WordObject obj) FileOutputStream f_out = new

Type 'System.Web.HttpRequest' cannot be serialized

匆匆过客 提交于 2019-12-25 18:29:01
问题 I am trying to design an Picture Upload feature into a web site. I am using ASP.NET 3.5, C#, and WCF. I have been asked to accomplish the following: 1) Make the Uploader a Web Service 2) Return progress updates to the user as files are uploaded. 3) Log other relevant user-selected options in the database. So, I have started off by creating a WCF web client with the below service contract: IService.UploadPictures(HttpRequest request); private UploadServiceClient upload; protected void Page