serialization

Generics and ReadObject

◇◆丶佛笑我妖孽 提交于 2020-01-14 01:36:11
问题 I have a simple server that uses generics and object serialization. (T is the input format, U is the output format). A simplified version that only deals with input is shown below: public class Server <T, U> implements Runnable { @override public void run () { try (ObjectInputStream inReader = new ObjectInputStream (this.connection.getInputStream ())) { T lastObj; while (true) { lastObj = (T) inReader.readObject (); System.out.println (lastObj.getClass ().getName ()); if (null != lastObj) {

Is it possible to serialize a grouped list?

早过忘川 提交于 2020-01-13 20:35:07
问题 I want to serialize grouped list. but I am getting error. Is it possible to serialize a grouped list? if yes then How? Error : Cannot serialize interface System.Linq.IGrouping`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[MyProject.MyNamespace.Elements, MyProject.MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. Code : MemoryStream memoryStream = new MemoryStream(); List<IGrouping<string, Elements>> lstGroupedElements =

XmlSerialization of mutiple object types in the one list

北城以北 提交于 2020-01-13 19:57:27
问题 I have an object that has a list of abstract 'aninamls'. i.e. var animals = new Animals { new Bird{ TailFeatherColour = "Blue" }, new Cat{ Colour = "Brown" } }; using the xmlserializer, is it possible to serialize the above to the following xml, <?xml version="1.0" encoding="utf-16"?> <Animals> <Bird> <TailFeatherColour>Blue</TailFeatherColour> </Bird> <Cat> <Colour>Brown</Colour> </Cat> </Animals> at the moment, I can only get the following: <?xml version="1.0" encoding="utf-16"?> <Animals>

XmlSerialization of mutiple object types in the one list

孤人 提交于 2020-01-13 19:57:09
问题 I have an object that has a list of abstract 'aninamls'. i.e. var animals = new Animals { new Bird{ TailFeatherColour = "Blue" }, new Cat{ Colour = "Brown" } }; using the xmlserializer, is it possible to serialize the above to the following xml, <?xml version="1.0" encoding="utf-16"?> <Animals> <Bird> <TailFeatherColour>Blue</TailFeatherColour> </Bird> <Cat> <Colour>Brown</Colour> </Cat> </Animals> at the moment, I can only get the following: <?xml version="1.0" encoding="utf-16"?> <Animals>

Newtonsoft.json serializing and deserializing base/inheirited where classes are from shared projects

血红的双手。 提交于 2020-01-13 19:41:08
问题 So I have two classes like the ones below. They are both in the same namespace and in the same shared project. public class Person{ public string Name{get;set;} } public class EmployedPerson : Person{ public string JobTitle{get;set;} } When I serilize these items into rabbitmq I am serializing as the base class like so: JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, TypeNameHandling = TypeNameHandling

Android Java — Deserializing a file on the Android platform

ε祈祈猫儿з 提交于 2020-01-13 19:36:13
问题 I have a jave program that serializes files that are stored and read later. So I take the serialized files and try to read them in on my Android phone (working in Eclipse) using the exact same code I used in Java SE: FileInputStream fis = null; try { fis = new FileInputStream("iwastedahalfhouronthis.ser"); } catch (FileNotFoundException ex) { } FileNotFoundException thrown. So ok, its probably not in the right place. So I place the file in every possible folder within the Eclipse project and

How do I invoke WriteJson recursively?

二次信任 提交于 2020-01-13 19:10:42
问题 I use Json.Net. When I serialize a Department2 object and WriteJson() is invoked I want it to be recursively invoked with each of the Telephone2 objects like I do in ReadJson() . How do I do that? using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public interface ISimpleDatabag { string Databag { get; set; } } [JsonConverter(typeof(JsonDataBagCreationConverter<Department2>))] public class Department2 { public Telephone2[] Phones { get; set; } } [JsonConverter(typeof

Why and how does python truncate numerical data?

∥☆過路亽.° 提交于 2020-01-13 17:48:58
问题 Am dealing with two variables here, but confused because their values seem to be changing (they loose precision) when I want to send them as URL parameters as they are. Look at this scenario as I reproduce it here from the python interpreter: >>> lat = 0.33245794180134 >>> long = 32.57355093956 >>> lat 0.33245794180133997 >>> long 32.57355093956 >>> nl = str(lat) >>> nl '0.332457941801' >>> nlo = str(long) >>> nlo '32.5735509396' So what is happening? and how can I ensure that when I

c# serialized JSON date to ruby

大城市里の小女人 提交于 2020-01-13 13:53:02
问题 I have a C# application that serializes its DTOs to JSON and sends them accros the wire to be processed by Ruby. Now the format of the serialized date is like so: /Date(1250170550493+0100)/ When this hits the Ruby app I need to cast this string representation back to a date/datetime/time (whatever it is in Ruby). Any ideas how I would go about this? Cheers, Chris. 回答1: You could parse out the milliseconds since the epoch, something like: def parse_date(datestring) seconds_since_epoch =

c# serialized JSON date to ruby

我们两清 提交于 2020-01-13 13:52:44
问题 I have a C# application that serializes its DTOs to JSON and sends them accros the wire to be processed by Ruby. Now the format of the serialized date is like so: /Date(1250170550493+0100)/ When this hits the Ruby app I need to cast this string representation back to a date/datetime/time (whatever it is in Ruby). Any ideas how I would go about this? Cheers, Chris. 回答1: You could parse out the milliseconds since the epoch, something like: def parse_date(datestring) seconds_since_epoch =