deserialization

Deserialize json based on fields in .Net (C#)

陌路散爱 提交于 2020-01-01 03:10:50
问题 I'm writing an app that gets a Json list of objects like this: [ { "ObjectType": "apple", "ObjectSize": 35, "ObjectCost": 4, "ObjectTaste": "good", "ObjectColor": "golden" }, { "ObjectType": "books", "ObjectSize": 53, "ObjectCost": 7, "Pages": 100 }, { "ObjectType": "melon", "ObjectSize": 35, "ObjectTaste": "good", "ObjectCost": 5 }, { "ObjectType": "apple", "ObjectSize": 29, "ObjectCost": 8, "ObjectTaste": "almost good", "ObjectColor": "red" } ] I want to make a base class ItemToSell (size

Deserialize json based on fields in .Net (C#)

帅比萌擦擦* 提交于 2020-01-01 03:10:29
问题 I'm writing an app that gets a Json list of objects like this: [ { "ObjectType": "apple", "ObjectSize": 35, "ObjectCost": 4, "ObjectTaste": "good", "ObjectColor": "golden" }, { "ObjectType": "books", "ObjectSize": 53, "ObjectCost": 7, "Pages": 100 }, { "ObjectType": "melon", "ObjectSize": 35, "ObjectTaste": "good", "ObjectCost": 5 }, { "ObjectType": "apple", "ObjectSize": 29, "ObjectCost": 8, "ObjectTaste": "almost good", "ObjectColor": "red" } ] I want to make a base class ItemToSell (size

Jackson custom deserializer for one field with polymorphic types

别说谁变了你拦得住时间么 提交于 2020-01-01 01:16:09
问题 Update: I tried to debug in jackson source code and find out that in the method deserialize(JsonParser jp, DeserializationContext ctxt) of SettableBeanProperty.java when the _valueTypeDeserializer isn't null, it will never use _valueDeserializer . Is this a correct assumption that TypeDeserializer should be more proper than ValueDeserializer? I'm trying to use @JsonDeserialize to define custom deserializer for one field with polymorphic types. I can succeed to use @JsonDeserialize and

protobuf.net & conditional serialization

别来无恙 提交于 2019-12-31 04:49:07
问题 We are using protobuf.net to serialize classes between mobile devices and back end services, but we now need to adjust what is sent back to the client based upon the 'context' of the user. We would typically do this by implementing the ISerializable interface and look at the context value to then decide what to serialize. Similarly in the constructor we would then deserialize the provided values. But it would appear that ISerializable isn't implemented/support (i can see why) for protobuf.net

c#: Deserializing xml with namespaces to clr object

送分小仙女□ 提交于 2019-12-31 03:52:05
问题 I need some help with XmlSerializer. I have to following xml fragment: <?xml version='1.0' encoding='UTF-8'?> <?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'> <id>tag:blogger.com,1999:blog-4233645339430781865.archive</id>

C# Deserialization xml file

青春壹個敷衍的年華 提交于 2019-12-31 03:42:06
问题 I try to deserialize xml file: <?xml version="1.0" encoding="utf-8"?> <XmlFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <OBJECTS ITEM="ItemValue" TABLE_NAME="TableExample"> </OBJECTS> </XmlFile> My deserialize class code looks like that: [Serializable] [XmlRoot("XmlFile")] public class SerializeObject { [XmlAttribute("ITEM")] public string Item { get; set; } [XmlAttribute("TABLE_NAME")] public string Table_Name { get; set; } } When I

Issue deserializing encrypted data using BinaryFormatter

廉价感情. 提交于 2019-12-31 03:09:03
问题 Here is my code: public static void Save<T>(T toSerialize, string fileSpec) { BinaryFormatter formatter = new BinaryFormatter(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); using (FileStream stream = File.Create(fileSpec)) { using (CryptoStream cryptoStream = new CryptoStream(stream, des.CreateEncryptor(key, iv), CryptoStreamMode.Write)) { formatter.Serialize(cryptoStream, toSerialize); cryptoStream.FlushFinalBlock(); } } } public static T Load<T>(string fileSpec) {

JSON to Java Objects, best practice for modeling the json stream

删除回忆录丶 提交于 2019-12-31 01:52:12
问题 I have a JSON stream being generated by a server side C++ program that is currently in development. I've been given a sample of the resulting JSON and I am concerned that I will have to parse the json by hand, that I won't be able to use normal class mapping provided by tools such as GSON or Jackson. Please take a look at the following (somewhat) contrived example they have provided. The sections I'm concerned with are the meta data "serie" array having different parameters. The key - "key"

newbie: append serialized integers into database column and retrieve them back

安稳与你 提交于 2019-12-30 11:53:41
问题 How Could I store integers (user id's ranging from 1 to 9999) serialized in a database column and retrieve them back? In my User model I have invites column, User model serialize: invites invites = text field Now I'm trying to do 2 things: Append the user_id integer (from 1 to 9999) serialized in a column "invites" Retrieve all the user id's back from the User.invited column ( deserialize it ? ) 回答1: From the fine manual: serialize(attr_name, class_name = Object) If you have an attribute that

JsonMappingException: Can not find a deserializer for non-concrete Map type

坚强是说给别人听的谎言 提交于 2019-12-30 11:08:36
问题 String str = commonClient.authorizedRequestBuilder(commonClient.webTarget .path("/apps/get_current_version/default/"+appName+"/"+appName) .queryParam("object_type", "app")) .accept(MediaType.APPLICATION_JSON_TYPE) .get() .readEntity(String.class); i get str = {"versions": {"ap": "Not Set", "am": "topic-test-publisher-1.0.16", "il": "topic-test-publisher-1.0.16", "row": "topic-test-publisher-1.0.49"}, "provider": "gce"} Then i have changed to this code Version version = commonClient