deserialization

Deserialize JSON Array to Object with private list property using Jackson

↘锁芯ラ 提交于 2020-01-17 08:14:09
问题 A JSON string like: [ "a", "b", "c" ] Would usually be deserialized to List<String> . But I have a class that looks like this: public class Foo { private List<String> theList; public Foo(List<String> theList) { this.theList = theList; } public String toString() { return new ObjectMapper().writeValueAsString(theList); } // ... more methods } Now I want to deserialize the above JSON string into an object of class Foo like: Foo foo = new ObjectMapper().readValue(jsonString, Foo.class); How is

If Dill file is too large for RAM is there another way it can be loaded

随声附和 提交于 2020-01-17 05:38:06
问题 If a dill file is to large to RAM, is it possible to load it in an alternative method. For example python3 is throwing Memory Errors when I load a serialized object of about 1.2 GB. file = open('SerializedData.pkl', 'rb') data = dill.load(file) This will not pass because the RAM is too small. However, is it possible to load it in a different way so that I extract the data without overloading the RAM? 来源: https://stackoverflow.com/questions/32465186/if-dill-file-is-too-large-for-ram-is-there

Deserialization problem: Error when deserializing from a different program version

自古美人都是妖i 提交于 2020-01-17 02:53:30
问题 I finally decided myself to post my problem, after a couple of hours spent searching the Internet for solutions and trying some. [Problem Context] I am developing an application which will be deployed in two parts: an XML Importer tool: its role is to Load/Read an xml file in order to fill some datastructures, which are afterwards serialized into a binary file. the end user application: it will Load the binary file generated by the XML Importer and do some stuff with the recovered data

Deserializing JSON using System.Runtime.Serialization.Json

一个人想着一个人 提交于 2020-01-15 06:53:57
问题 I'm having issues with deserializing some json with C#. Suppose this is a snippet of the json I'm being sent (repeated many times, but nothing else other than id/name): [ { "id":0, "name":"N/A" }, { "id":1, "name":"Annie" }, { "id":2, "name":"Olaf" } ] If the top level was named, I'd do something like [DataContract] public class ChampList { [DataMember(Name = "SOMENAME")] public ElophantChamp[] ElophantChamps { get; set; } } [DataContract] public class ElophantChamp { [DataMember(Name = "id")

Decoding unknown Encodable enum values to a default

限于喜欢 提交于 2020-01-14 10:16:07
问题 I have to deserialize a JSON string like this: { "name" : "John Smith", "value" : "someValue" } in Swift 4, where "value" should be a enum and the whole object is a struct like: struct MyType { name: String? value: Value? } At some point in the future, there might be new enum values added in the backend so I thought it would be smart to have some fallback. I thought I could create a enum like enum Value { case someValue case someOtherValue case unknown(value: String) } but I just can't wrap

Implicit default values when deserializing JSON using Jackson

自闭症网瘾萝莉.ら 提交于 2020-01-14 08:15:28
问题 When deserializing a variety of JSON messages, I want to provide a default value for attributes of a certain type. It is generally suggested to simply specify the value in the Class, but this is error-prone if you have to do this across many Classes. You might forget one and end up with null instead of a default value. My intention is to set every property that is an Optional<T> to Optional.absent . Since null is exactly what Optional is trying to eliminate, using them with Jackson has proven

sequentially deserialize using Jackson

心不动则不痛 提交于 2020-01-14 06:40:43
问题 I have a value object serialized and deserialized using Jackson. The VO has two fields: x and y. But invoking setY makes sense only when x is set. Is there any way I can make sure that setX is invoked earlier than setY during de-serialization? 回答1: You can do it only by implementing custom deserializer for your POJO (VO) class. Let assume that you POJO class looks like this: class Point { private int x; private int y; //getters, setters, toString } Now, you can implement deserializer. You can

How to determine which constructor Autofac uses when resolving

孤者浪人 提交于 2020-01-14 03:15:22
问题 I'm using a custom JsonConverter and JsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects to create the required instances during deserialization. The instances are created by resolving the types from an Autofac IOC container. Everything works fine, except... I have several "core objects" that request a unique Id in the constructor from a service (which is correctly injected into the constructor). When deserializing this should not happen because it is fairly expensive and the

JSON.Net constructor parameter missing when deserializing

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 19:06:59
问题 I have a simple object that I'm roundtripping through JSON. It serializes just fine, but I deserialize it one of the values is set to the default value (0, in this particular case). Why is that? Here's my object: public class CurrencyExchangeRate { public string CurrencyCode { get; private set; } public decimal Rate { get; private set; } public CurrencyExchangeRate(string currencyCode, decimal exchangeRate) { this.CurrencyCode = currencyCode; this.Rate = exchangeRate; } } This serializes to

Deserializing a list of objects with different names in JSON.NET

ぃ、小莉子 提交于 2020-01-13 11:28:32
问题 I'm getting my data from a website which returns a .json format that is quite unfamiliar to me. I've been looking for the solution for a couple of hours, and I must be using the terminology. The json is formatted something like this: [ { "Foo": { "name": "Foo", "size": { "human": "832.73kB", "bytes": 852718 }, "date": { "human": "September 18, 2017", "epoch": 1505776741 }, } }, { "bar": { "name": "bar", "size": { "human": "4.02MB", "bytes": 4212456 }, "date": { "human": "September 18, 2017",