serialization

How can I deserialize an object if I don't know the right type?

可紊 提交于 2019-12-24 17:23:08
问题 Well I want to send commands and data between client and server. I have three projects: Client Server Common - here I put common classes and network abstraction layer I am using following data structures for communications between client and server public class Packet<T> { public string Name { get; set; } public string From { get; set; } public string To { get; set; } public PacketType PacketType { get; set; } public T Container { get; set; } public Packet() { } public Packet(string name,

How to retrieve $_POST variable from jquery serializearray()

余生颓废 提交于 2019-12-24 17:05:19
问题 I have a problem in retrieving the $_POST data from jquery serializeArray(); . I tried to for loop the $_POST to get the data but failed. This is my JavaScript code: function update_cart(){ var fields = $(':input').serializeArray(); console.log(fields); var url = "update_cart.php"; $.post(url, {fields:fields}, function(data) { alert(data); }, "html"); return false; } In my PHP code : var_dump($_POST); The result is this: array(1) {["fields"]=> string(15) "[object Object]"} So, can anyone

Serializing data using XmlArrayItemAttribute not working well

时间秒杀一切 提交于 2019-12-24 17:02:08
问题 I have this DataContract, which is an array of strings: [System.Xml.Serialization.XmlArrayAttribute(Order = 19)] [System.Xml.Serialization.XmlArrayItemAttribute("CardNumber", typeof(string), IsNullable = false)] [DataMember] public string[] Cards {get; set; } As I read, it should be serialized like this: <Cards> <CardNumber>123123</CardNumber> </Cards> but I'm still getting: <Cards> <string>123123</string> </Cards> What's wrong with it? 回答1: You can use CollectionDataContract instead. First,

Java how to use Jackson ObjectMapper to concatenate two fields in Item class during serialization?

∥☆過路亽.° 提交于 2019-12-24 17:00:01
问题 I have a class: public class Item { private String firstName; private String lastName; private int age; } When I convert it to JSON, I would like to combine the firstName and lastName fields. So something like: ObjectMapper objMapper = createMapper(); Item item = new Item("Bob", "Smith", 190); String json = objMapper.writeValueAsString(item); But I would like the json to look as follows: { "Name": "Bob Smith", "age" : "190" } instead of: { "firstName": "Bob", "lastName" : "Smith", "age" :

AMQP(RabbitMQ) Could not deserialize object, ClassNotFoundException

时光毁灭记忆、已成空白 提交于 2019-12-24 16:54:25
问题 I want to implement a RabbitMq(AMQP) messaging in java SpringBoot, but when I receive the message it says that the messaGE could not be deserialize because I the class for the object that I supposed to receive was not found even if I have that class int the classpath. RabbitMqListener.java: @EnableRabbit @Component public class RabbitMqListener { Logger logger = Logger.getLogger(RabbitMqListener.class); @RabbitListener(queues = "queue2") public void processQueue1(Product message) { logger

How to get serialized XML of object passed to web service?

别说谁变了你拦得住时间么 提交于 2019-12-24 16:41:02
问题 I have a VB.NET (2008) console application which consumes a web service. All is working fine -- I've used WSDL.exe to import the web service's definition and create the appropriate classes, I can interact with those classes to fill them up with data, and the call to the web service succeeds and data is passed. However, after the successful transfer of data, I would like to log this event to a table in my Oracle database -- including the XML that was transferred (for review at a later time, in

How to get serialized XML of object passed to web service?

自古美人都是妖i 提交于 2019-12-24 16:40:03
问题 I have a VB.NET (2008) console application which consumes a web service. All is working fine -- I've used WSDL.exe to import the web service's definition and create the appropriate classes, I can interact with those classes to fill them up with data, and the call to the web service succeeds and data is passed. However, after the successful transfer of data, I would like to log this event to a table in my Oracle database -- including the XML that was transferred (for review at a later time, in

Serialize ModelStateDictionary to XML

依然范特西╮ 提交于 2019-12-24 16:39:40
问题 I try to serialize the ModelStateDictionary to a XML string. I tried with the .net XML serialization class like this: XmlSerializer serializer = new XmlSerializer(typeof(ModelStateDictionary)); TextWriter textWriter = new StreamWriter("c:\\files\\text.xml"); serializer.Serialize(textWriter,this.ModelState); textWriter.Close(); The result was: <?xml version="1.0" encoding="utf-8"?> <ArrayOfKeyValuePairOfStringModelState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:/

Modify the behaviour of JSON.NET to serialize a collection of objects to an array of IDs

谁说我不能喝 提交于 2019-12-24 16:31:44
问题 I want to modify JSON.NET so that when I am serializing a Model from my API it sends only an array of IDs for a composite Collection object. For example: class Employee { public ICollection<Address> Addresses { get; set; } } class Address { public int id; public string location; public string postcode; } Then when I send that back through WebApi Request.Createresponse(HttpStatusCode.OK, new Employee()); Instead of this: { "Addresses" : [ {"id" : 1, "location" : "XX", "postcode" : "XX" }, {"id

Serialize object along with static member variables to XML [duplicate]

断了今生、忘了曾经 提交于 2019-12-24 16:16:52
问题 This question already has answers here : Serialize a Static Class? (6 answers) Closed 6 years ago . I have the following object that contains a static member variable. What I would like to do is serialize this object and save it to XML. Unfortunately, the code below does not seem to do the job. I would appreciate any help in getting this working please. [Serializable] public class Numbers { public int no; public static int no1; public SubNumbers SubNumber; } [Serializable] public class