deserialization

Jackson Polymorphic Deserialization via field

a 夏天 提交于 2021-02-19 06:18:05
问题 let's say, i have a class public class A{ private UUID typeId; private B data; } public abstract class B{ private String a; } public class BChildOne extends B{ ... some variables } public class BChildTwo extends B{ ... some variables } type of class B is changing, according to A's typeId , so if typeId of A is "XXX", type of data field is BChildOne, and if typeId of A is "YYY", type of data field is BChildTwo. how can i achive that? so for i tried that; @JsonAutoDetect(fieldVisibility =

Mapping XML to classes in c#

僤鯓⒐⒋嵵緔 提交于 2021-02-18 23:30:51
问题 I'm looking to map multiple XML attributes in nested elements into a single POCO class using the XmlSerializer object. XML <products grand-total="100"> <one price="50" /> <two price="20" /> <tree price="30" /> </products> POCO public class Product { public int GrandTotal { get; set; } public int OnePrice { get; set; } public int TwoPrice { get; set; } public int ThreePrice { get; set; } } C# var doc = XDocument.Load("XmlDoc.xml"); var serializer = new XmlSerializer(typeof(Product)); var

Serializing Timespan in Dictionary<string, object> with Json.NET

主宰稳场 提交于 2021-02-16 14:21:46
问题 I have a property that is actually a Dictionary. And I keep many types in this dictionary like TimeSpans, DateTimes, etc. But serializing and deserializing TimeSpans are wrong and it deserializes as string. var dict = new Dictionary<string, object>(); dict.Add("int", 15); dict.Add("string", "foo"); dict.Add("timeSpan", new TimeSpan(1,1,1)); dict.Add("dateTime", DateTime.Now); var settings = new JsonSerializerSettings{ TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat =

Why is ObjectInputStream.readUnshared() 1000x slower than ObjectOutputStream.writeUnshared()?

亡梦爱人 提交于 2021-02-11 17:51:06
问题 I'm working on a pair of classes that queue up a large quantity of objects, and then allow for that queue to be iterated over, using Java Serialization/ ObjectOutputStream & ObjectInputStream. The quantity of data needed in the queue is in excess of 50GB, hence the need for file IO. The problem is that a file that takes 2ms to write takes ~2 seconds to read. I've tried BufferedInputStream, and each reader has a dedicated thread to keep the input buffer full. private File file; private

Why is ObjectInputStream.readUnshared() 1000x slower than ObjectOutputStream.writeUnshared()?

岁酱吖の 提交于 2021-02-11 17:51:03
问题 I'm working on a pair of classes that queue up a large quantity of objects, and then allow for that queue to be iterated over, using Java Serialization/ ObjectOutputStream & ObjectInputStream. The quantity of data needed in the queue is in excess of 50GB, hence the need for file IO. The problem is that a file that takes 2ms to write takes ~2 seconds to read. I've tried BufferedInputStream, and each reader has a dedicated thread to keep the input buffer full. private File file; private

Python 3 numpy.load() until End of File

孤人 提交于 2021-02-11 12:27:10
问题 Suppose I'm generating a random number of arrays that I need to serialize def generator(): num = 0 while num < random.randint(0, 10): yield np.array(range(2)) num += 1 with open('out.npy', 'wb') as f: for item in generator(): np.save(f, item) Now how do I know exactly how many times I have to np.load() to get all the arrays back? np.load() will eventually throw an exception so I came up with with open('out.npy', 'rb') as f: try: while 1: item = np.load(f) print(item) except: print("EoF") but

Custom JSON Deserialization in C# with JsonConverter

孤街醉人 提交于 2021-02-11 06:51:10
问题 I have two classes in .Net Core The class Ownership namespace CustomStoreDatabase.Models { public class Ownership { public string OwnershipId { get; set; } public List<string> TextOutput { get; set; } public DateTime DateTime { get; set; } public TimeSpan MeanInterval { get; set; }// Like long ticks, TimeSpan.FromTicks(Int64), TimeSpan.Ticks } } I need to show MeanInterval like long ticks, using the methods TimeSpan.FromTicks(Int64) and TimeSpan.Ticks . My custom JsonConverter using

Deserialize json dictionary to c#

假如想象 提交于 2021-02-10 19:52:51
问题 I'm getting this json from an API. string json = "{'serviceSession':{ '123123123':[{'apn':'abc'},{'apn':'bcd'},{'apn':'def'}]}}"; When I'm trying to deserialize it with public class ServiceSession { public Dictionary<string, List<ServiceSessionType>> ServiceSessions { get; set; } } public class ServiceSessionType { public string Apn { get; set; } } and var test = JsonConvert.DeserializeObject<ServiceSession> (json); I'm getting null. What's wrong? any ideas? Thank you in advance!! 回答1: There

Deserialize JSON and assign to model

时光毁灭记忆、已成空白 提交于 2021-02-10 18:33:55
问题 As part of my web api, I'm getting the following JSON returned. ["{\"InputType\":17,\"EngineSubType\":4,\"Filename\":\"targetFile.csv\",\"FileExtensionType\":\".csv\",\"IsLoadFile\":true,\"LoadContextId\":4121,\"ReportingDate\":\"2019-05-31T00:00:00\",\"IsSuccess\":false}"] What I'm wanting to do is grab the value next to Filename and assign it to my models Filename parameter. In my project I've created a unit test to experiment with grabbing that value, but each attempt I've making is

Unity Json De/serializing nested data [duplicate]

主宰稳场 提交于 2021-02-10 14:19:16
问题 This question already has answers here : Serialize and Deserialize Json and Json Array in Unity (9 answers) Closed 3 years ago . please help me! I'm trying to read a big chunk of data from a json file and most part of the data is a list of list! I dont know how to deserialize it! So I found this guide, and did as him using the JsonFX http://www.raybarrera.com/2014/05/18/json-deserialization-using-unity-and-jsonfx/ it helped me deserialize all the other information I need except the list of