deserialization

Ignore a property during xml serialization but not during deserialization

我与影子孤独终老i 提交于 2019-12-17 08:56:09
问题 In C#, how can I make XmlSerializer ignore a property during serialization but not during deserialization? (Or how do I do the same with Json.net?) To prevent a property from being serialized, you can add the XmlIgnore attribute: [XmlIgnore] public int FooBar {get;set;} This will cause the <FooBar> tag to be omitted during serialization. However, this also means that the <FooBar> tag will be ignored during deserialization. In my case, I accept an array of items from user in the request, and

Serializing/deserializing with memory stream

霸气de小男生 提交于 2019-12-17 07:20:01
问题 I'm having an issue with serializing using memory stream. Here is my code: /// <summary> /// serializes the given object into memory stream /// </summary> /// <param name="objectType">the object to be serialized</param> /// <returns>The serialized object as memory stream</returns> public static MemoryStream SerializeToStream(object objectType) { MemoryStream stream = new MemoryStream(); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, objectType); return stream; } ///

property type or class using reflection

六月ゝ 毕业季﹏ 提交于 2019-12-17 06:43:51
问题 I was wondering if it's possible to determine the class or primitive type of an Objects properties. Getting all properties names and values is pretty easy. SO answer So is there any way to get the properties class type while the property hast no value or nil value? Example Code @interface MyObject : NSObject @property (nonatomic, copy) NSString *aString; @property (nonatomic, copy) NSDate *aDate; @property NSInteger aPrimitive; @end @implementation MyObject @synthesize aString; @synthesize

property type or class using reflection

╄→尐↘猪︶ㄣ 提交于 2019-12-17 06:43:49
问题 I was wondering if it's possible to determine the class or primitive type of an Objects properties. Getting all properties names and values is pretty easy. SO answer So is there any way to get the properties class type while the property hast no value or nil value? Example Code @interface MyObject : NSObject @property (nonatomic, copy) NSString *aString; @property (nonatomic, copy) NSDate *aDate; @property NSInteger aPrimitive; @end @implementation MyObject @synthesize aString; @synthesize

GSON deserializing key-value to custom object

十年热恋 提交于 2019-12-17 06:41:23
问题 I need to deserialize json which is an array of date/long values. Here is an example of the returned JSON: [{"2011-04-30T00:00:00-07:00":100}, {"2011-04-29T00:00:00-07:00":200}] Using GSON I am able to deserialize this to a List<Map<Date,String>> , but would like to be able to convert it to a List<MyCustomClass> similar to: public class MyCustomClass() { Date date; Long value; } I cannot seem to find a way to instruct GSON to map the key/value of the JSON map to the date/value fields in my

Deserializing polymorphic types with Jackson

不羁的心 提交于 2019-12-17 06:09:41
问题 If I have a class structure like so: public abstract class Parent { private Long id; ... } public class SubClassA extends Parent { private String stringA; private Integer intA; ... } public class SubClassB extends Parent { private String stringB; private Integer intB; ... } Is there an alternative way to deserialize different then @JsonTypeInfo ? Using this annotation on my parent class: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "objectType") I would rather not have to force

Jackson Change JsonIgnore Dynamically

感情迁移 提交于 2019-12-17 06:08:07
问题 I have a class and there are variables inside it as well. Sometimes I want to ignore some fields and sometimes not when deserializing (maybe at serializing too). How can I do it at Jackson? 回答1: For serialization, "filtering properties" blog entry should help. Deserialization side has less support, since it is more common to want to filter out stuff that is written. One possible approach is to sub-class JacksonAnnotationIntrospector , override method(s) that introspect ignorability of methods

How do I deserialize a complex JSON object in C# .NET?

不问归期 提交于 2019-12-17 03:16:31
问题 I have a JSON string and I need some help to deserialize it. Nothing worked for me... This is the JSON: { "response": [{ "loopa": "81ED1A646S894309CA1746FD6B57E5BB46EC18D1FAff", "drupa": "D4492C3CCE7D6F839B2BASD2F08577F89A27B4ff", "images": [{ "report": { "nemo": "unknown" }, "status": "rock", "id": "7e6ffe36e-8789e-4c235-87044-56378f08m30df", "market": 1 }, { "report": { "nemo": "unknown" }, "status": "rock", "id": "e50e99df3-59563-45673-afj79e-e3f47504sb55e2", "market": 1 } ] }] } I have an

How to Read XML to Class Object

房东的猫 提交于 2019-12-14 04:12:11
问题 I have an XML like this: <?xml version="1.0" standalone="yes"?> <DocumentElement> <Session> <bIsImages>False</bIsImages> <bIsPlayMedia>False</bIsPlayMedia> <bIsSubject>False</bIsSubject> <bIsVideo>False</bIsVideo> <dtCreDate>2012-07-23</dtCreDate> <dtSes_Date1>2001-01-01</dtSes_Date1> <dtSes_Date2>2001-01-01</dtSes_Date2> <dtSes_Date3>2001-01-01</dtSes_Date3> <nClient_ID>32</nClient_ID> <nDelay>32</nDelay> <nImage_ID>32</nImage_ID> <nOperator_ID>32</nOperator_ID> <nSession_ID>32</nSession_ID>

How does one properly deserialize a byte array back into an object in C++?

人盡茶涼 提交于 2019-12-14 03:21:48
问题 My team has been having this issue for a few weeks now, and we're a bit stumped. Kindness and knowledge would be gracefully received! Working with an embedded system, we are attempting to serialize an object, send it through a Linux socket, receive it in another process, and deserialize it back into the original object. We have the following deserialization function: /*! Takes a byte array and populates the object's data members */ std::shared_ptr<Foo> Foo::unmarshal(uint8_t *serialized,