serialization

Deserializing MongoDB BSON

∥☆過路亽.° 提交于 2019-12-22 08:55:38
问题 I attempting to take a response from a REST service that queries an instance of MongoDB and parse the response into a Java object. The web service returns the response with a MIME type of html with a newline character separating each record that is returned (although I have the ability to adjust what the service returns). What is the easiest/most efficient way for converting the BSON response into a Java object? I have already created a template class in Java to store the data. Thanks in

What is the more elegant way to serialize my own objects with arrays in Swift

和自甴很熟 提交于 2019-12-22 08:54:56
问题 I have a classes that looks like this: class Foo { var bar = Int() } class Bar { var baz = String() var arr = [Foo]() } and I have an object of Bar structure that I need to serialize to JSON: let instance = Bar() What is the more elegant way to do it via standard library or some third-party libraries? Thanks in advance. 回答1: I suggest taking this approach: class Foo { var bar = Int() } class Bar { var baz = String() var arr = [Foo]() var jsonDictionary: NSDictionary { return [ "baz" : self

Make JsonNode Serializable

佐手、 提交于 2019-12-22 08:54:54
问题 This seems to be simple but I failed to get a serialized JsonNode deserialized. Here is my test class import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Foo implements Serializable { private String string; private transient JsonNode jsonNode; public Foo(String string, JsonNode jsonNode) { this.string =

XML object serialization in python, are there any alternatives to Gnosis?

前提是你 提交于 2019-12-22 08:50:14
问题 For a while I've been using a package called "gnosis-utils" which provides an XML pickling service for Python. This class works reasonably well, however it seems to have been neglected by it's developer for the last four years. At the time we originally selected gnosis it was the only XML serization tool for Python. The advantage of Gnosis was that it provided a set of classes whose function was very similar to the built-in Python XML pickler. It produced XML which python-developers found

WCF Data Contract / Serialization

流过昼夜 提交于 2019-12-22 08:37:14
问题 I created a simple WCF application which expose one operation. This operation takes a composite data type as parameter. I have not decorated this composite data type with [DataContract] attribute. But this is working and I can see the Schema for this in WSDL. Now my understanding is that this new custom type should be decorated with [Serializable] or [dataContract] attribute to take part in the Web services operation. What I am missing here? 回答1: POCO support have been introduced in WCF since

Json.Net messes up timezones for DateTimeOffset when serializing

房东的猫 提交于 2019-12-22 08:33:59
问题 I have looked at a lot of related questions but none of them seem to be working for me. I'm trying to serialize everything in UTC. Here's my code: class Class1 { static void Main() { Class2 foo = new Class2(); JObject json = JObject.Parse(JsonConvert.SerializeObject(foo, new JsonSerializerSettings() { DateParseHandling = DateParseHandling.DateTimeOffset, DateFormatHandling = DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = DateTimeZoneHandling.Utc })); Console.WriteLine(json.ToString(

Serialize a struct/enum to bytes [duplicate]

蹲街弑〆低调 提交于 2019-12-22 08:17:40
问题 This question already has answers here : How to convert 'struct' to '&[u8]'? (2 answers) Closed 3 years ago . I'd like to serialize my struct to binary and de-serialize it on the other end of the pipe. Is there a way to achieve this with the serialize crate? It seems to only support JSON, hex and base64. 回答1: I would suggest bincode. It provides encode() and decode() functions which operate on anything with RustcEncodable & RustcDecodable traits, which can generally be #[derive] d, and return

C# object to XML

孤街浪徒 提交于 2019-12-22 08:16:06
问题 I am creating an application which requires to convert c# object to XML. I am using XML Serializer class to achieve this. Here is the code snippet: public class Anwer { public int ID { get; set; } public string XML { get; set; } public Anwer(int ID, string XML) { this.ID = ID; this.XML = XML; } public Anwer() { } } Here is the main function: string AnswerXML = @"<Answer>1<Answer>"; List<Anwer> answerList = new List<Anwer>(); answerList.Add(new Anwer(1,AnswerXML)); AnswerXML = @"<Answer>2

How do I set the serialization options for the geo values using the official 10gen C# driver?

安稳与你 提交于 2019-12-22 08:13:36
问题 Considering this class: public class Location { public Coordinates Geo { get; set; } public Location() { Geo = new Coordinates(); } public class Coordinates { public decimal Lat { get; set; } public decimal Long { get; set; } } } I have a geospatial index on the collection set like { Geo: "2d" } . Unfortunately the driver tries to store lat/lon coordinates as strings, instead of numbers and I get an error that says Tue Mar 15 16:29:22 [conn8] insert database.locations exception 13026 geo

Serialize/Deserialize custom Map<Key, Object> in Jackson

夙愿已清 提交于 2019-12-22 08:05:28
问题 I have a pretty simple Map I want to serialize and deserialize in Jackson, but I can't get it to work. I have tried the following: @JsonSerialize(keyUsing=TurnKeySerializer.class) @JsonDeserialize(keyUsing = TurnKeyDeserializer.class) Map<TurnKey, PlayerTurn> publicTurns = new TreeMap<>(); @JsonIgnoreProperties(ignoreUnknown = true) @Data //Creates Getter/Setter etc public class TurnKey implements Comparable<TurnKey> { private final int turnNumber; private final String username; public