serialization

How to serialize object with List inside in C# using XElement?

半城伤御伤魂 提交于 2019-12-23 12:13:10
问题 I have object with members of different types like this: public class MyObject { public string Str1 = string.Empty; public MyEnums.Enum1 E1 = MyEnums.Enum1.Unknown; public bool Done = false; }; I have Dictionary of these objects: Dictionary<string, MyObject> MyObjectsDic = new Dictionary<string, MyObject>(); And serializer for it like this: public static void ToXml(string file, string collectionName, Dictionary<string, object> collection) { XElement root = new XElement(collectionName); root

RPC with protocol buffers

别等时光非礼了梦想. 提交于 2019-12-23 12:06:22
问题 I'm tring to make rpc with protocol buffers and zeromq. Here is my proto file: message SearchRequest { required string query = 1; } message SearchResponse { repeated Result result = 1; } message Result { required string url = 1; optional string title = 2; repeated string snippets = 3; } service SearchService { rpc Search (SearchRequest) returns (SearchResponse); } According to the tutorial I should get some service interface code and stubs for this rpc but I don't. Did I misunderstand

Receiving Json deserialized object as string in Web API controller

陌路散爱 提交于 2019-12-23 12:06:09
问题 Following is my Json input from Ui: { "data": [{ "Id": 1 }, { "Id": 2 }, { "Id": 3 }] } I can receive it without an issue in the object structure shown below: public class TestController : ApiController { /// <summary> /// Http Get call to get the Terminal Business Entity Wrapper /// </summary> /// <param name="input"></param> /// <returns></returns> [HttpPost] [Route("api/TestJsonInput")] public string TestJsonInput([FromBody] TestInput input) { return JsonConvert.SerializeObject(input.data)

eclipselink + @convert(json) + postgres + list property

折月煮酒 提交于 2019-12-23 11:58:22
问题 I'm using eclipselink 2.6 as a persistence provider of spring data jpa, that in my understanding, now allows you to serialize a subtree of an entity as json using the internal moxy serializer. So I'm trying to mix this to migrate from embedded element collections to a serialized json using the json datatype of postgres. I have an entity named Product, and this entity have the following mapped property: @Convert(Convert.JSON) private List<MetadataIndex> indexes=new ArrayList<MetadataIndex> ();

Custom XML serialization - Include class name

本秂侑毒 提交于 2019-12-23 11:57:10
问题 I'm after the following XML serialization output: <?xml version="1.0"?> <Message> <Version>1.0</Version> <Body> <ExampleObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <EmampleOne>Hello!</EmampleOne> </ExampleObject> </Body> </Message> I have the following classes: [Serializable] public class Message<T> { public string Version { get; set; } public T Body { get; set; } } [Serializable] public class ExampleObject { public string

Why is DataContractSerializer to StringWriter truncated?

。_饼干妹妹 提交于 2019-12-23 10:59:05
问题 I am using the DataContractSerializer to serialize EF4 objects to xml if there are exceptions. In my debug log i can see want was the data-content when something went wrong. I have two versions of code: one version that serializes to a file and one that serializes to a string using StringWriter . When serializing big items to file i get valid xml of about 16kb. when serializing the same item to string the xml is truncated after 12kb. Any idea what caused the truncation? ... var entity = ....

Jackson mapper with generic class in scala

寵の児 提交于 2019-12-23 10:54:55
问题 I am trying to serialise GeneralResponse : case class GeneralResponse[T](succeeded: Boolean, payload: Option[T]) and the payload is GroupsForUserResult : case class GroupsForUserResult(groups: Seq[UUID]). I am using mapper.readValue(response.body, classOf[GeneralResponse[GroupsForUserResult]]) but unfortunately the payload is serialised as a Map and not as the desired case class ( GroupForUserResult ). 回答1: Because of Java Erasure - Jackson can't know at runtime about the generic type T from

How can I override deserialization in C#

怎甘沉沦 提交于 2019-12-23 10:50:38
问题 I've got a class that will undergo certain version changes over the course of time. The data from inside this class is serialized and deserialized as part of the startup of my application. The problem I have is if I update the class by adding more properties, and then start the application, the old data does not get loaded properly. What I'm looking to do is override the deserialization step, I don't mind manually reconstructing the object from xml, as I have a version number stored and can

How to de-serialize XML with many child nodes

有些话、适合烂在心里 提交于 2019-12-23 10:49:11
问题 If my XML is like this: <Item> <Name>Jerry</Name> <Array> <Item> <Name>Joe</Name> </Item> <Item> <Name>Sam</Name> </Item> </Array> </Item> I can serialize it into this class: [DataContract(Namespace = "", Name = "dict")] public class Item { [DataMember(Name = "Name")] public string Name { get; set; } [DataMember(Name = "Array")] public IEnumerable<Item> Children { get; set; } } But what if my XML is like this? <Item> <Name>Jerry</Name> <Item> <Name>Joe</Name> </Item> <Item> <Name>Sam</Name> <

Maintain sub type information while serializing java objects using Jackson, without using wrapper class

a 夏天 提交于 2019-12-23 10:37:26
问题 I am trying to convert between a JSON file and an abstract class with two subclasses in Java using Jackson. Ideally, I would like to use a JSON as the following: Json document without wrapper [ { "type" : "lion", "name" : "Simba", "endangered" : true, "action" : "running" }, { "type" : "elephant", "name" : "Dumbo", "endangered" : false, "table" : [ 1.0, 2.0, 3.0 ] } ] I have annotated the Animal abstract class as shown on http://www.studytrails.com/java/json/java-jackson-Serialization