json-deserialization

How to unwrap Custom RuntimeException from Json Mapping Exception

偶尔善良 提交于 2020-01-06 05:16:08
问题 In a spring data rest project i use a custom RuntimeException to be called in a custom Deserializer public class LocalDateDeserializer extends StdDeserializer<LocalDate> { ... @Override public LocalDate deserialize(JsonParser jsonparser, DeserializationContext context) throws IOException, JsonProcessingException { String date = jsonparser.getText(); String name = jsonparser.getCurrentName(); try { return LocalDate.parse(date, DateTimeFormatter.ISO_LOCAL_DATE); } catch (DateTimeParseException

Json.Net Deserialization of Complex Objects - Base Class that Contains a Base Class as a Property

ぐ巨炮叔叔 提交于 2020-01-06 03:02:08
问题 I have been attempting to resolve this issue for several hours. I have tried many approaches and read many posts. I can't seem to find a resolution. I have an object hierarchy whereby I have derived types that contain another derived type. I am using Json.Net's TypeNameHandling setting. I have it set to Auto on both serialization and deserialization. The resulting JSON is: "[\r\n {\r\n \"$type\": \"Common.Monitors.HeartbeatMonitor, Common\",\r\n \"ClassName\": \"HeartbeatMonitor\",\r\n \

StackExchange API - Deserialize Date in JSON Response

≯℡__Kan透↙ 提交于 2020-01-03 20:13:28
问题 I am trying to use stackexchange api. In this link I am trying to get some users information. If you run, it you will get the JSON response. { "items": [ { "badge_counts": { "bronze": 5630, "silver": 4212, "gold": 267 }, "account_id": 11683, "is_employee": false, "last_modified_date": 1398827800, "last_access_date": 1398799412, "reputation_change_year": 34829, "reputation_change_quarter": 7965, "reputation_change_month": 7965, "reputation_change_week": 930, "reputation_change_day": 60,

StackExchange API - Deserialize Date in JSON Response

大兔子大兔子 提交于 2020-01-03 20:12:13
问题 I am trying to use stackexchange api. In this link I am trying to get some users information. If you run, it you will get the JSON response. { "items": [ { "badge_counts": { "bronze": 5630, "silver": 4212, "gold": 267 }, "account_id": 11683, "is_employee": false, "last_modified_date": 1398827800, "last_access_date": 1398799412, "reputation_change_year": 34829, "reputation_change_quarter": 7965, "reputation_change_month": 7965, "reputation_change_week": 930, "reputation_change_day": 60,

deserialization of a JSON API response with moshi

末鹿安然 提交于 2020-01-03 04:14:05
问题 I got a null object attributes after deserialization of a json response. Developing under android, I'm using retrofit2 , moshi as converter (https://github.com/kamikat/moshi-jsonapi ) . When debugging ,I saw a json response fully retrieved (not null attributes),but deserialization fails. Should I use GSON instead? Here's my retrofit builder I use to make my json call: (no issue) public static JsonServerInterface getSimpleClient(){ Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_AUTH

JSON deserialization of derived types

空扰寡人 提交于 2020-01-03 01:58:20
问题 class Attribute1 { } class Attribute2 : Attribute1 { } class class1 { Attribute1 attr1; } class class2 : class1 { Attribute2 attr2; } var serializerSettings = new JsonSerializerSettings(){TypeNameHandling = TypeNameHandling.Objects}; class2 a = SomeValidObjectoftype Class2; string serializedClass2 = JsonConvert.SerializeObject(a, serializerSettings); var am = JsonConvert.DeserializeObject<Class2>(serializedClass1); All the above are JSON properties and objects. What I am trying to do is

Json.net failing to load certain properties belonging to a class object?

二次信任 提交于 2019-12-31 07:24:46
问题 NOTE: I'm adding this community wiki entry to save someone the loss of time I just went through debugging this problem. I have a class object with multiple public properties. I can serialize it fine using JSON.net. But when I load the JSON text back and deserialize it using JsonConvert.DeserializeObject<> , some of the fields are set to NULL when they definitely had valid values at the time of serialization. I inspected the serialized JSON string manually and I definitely see values for the

Object reference error while reading specific JSON string?

醉酒当歌 提交于 2019-12-31 05:48:06
问题 I have used JSON to C# Class Converter and it generates the following Class: JSON {"ios_info":{"serialNumber":"F2LLMBNJFFF","imeiNumber":"01388400413235","meid":"","iccID":"8901410427640096045","firstUnbrickDate":"11\/27\/13","lastUnbrickDate":"11\/27\/13","unbricked":"true","unlocked":"false","productVersion":"7.1.2","initialActivationPolicyID":"23","initialActivationPolicyDetails":"US AT&T Puerto Rico and US Virgin Islands Activation Policy","appliedActivationPolicyID":"23",

Can I make a strict deserialization with Newtonsoft.Json?

一曲冷凌霜 提交于 2019-12-30 17:57:25
问题 I am using Newtonsoft.Json to serialize/deserialize objects. As far as I know a deserialization can not be successful if the class does not have parameterless constructor. Example, public class Dog { public string Name; public Dog(string n) { Name = n; } } For this class below code generates the object correctly. Dog dog1 = Newtonsoft.Json.JsonConvert.DeserializeObject<Dog>("{\"Name\":\"Dog1\"}"); For me, surprisingly it generates the object correctly with below codes also. Dog dog2 =

Can I make a strict deserialization with Newtonsoft.Json?

孤街浪徒 提交于 2019-12-30 17:57:04
问题 I am using Newtonsoft.Json to serialize/deserialize objects. As far as I know a deserialization can not be successful if the class does not have parameterless constructor. Example, public class Dog { public string Name; public Dog(string n) { Name = n; } } For this class below code generates the object correctly. Dog dog1 = Newtonsoft.Json.JsonConvert.DeserializeObject<Dog>("{\"Name\":\"Dog1\"}"); For me, surprisingly it generates the object correctly with below codes also. Dog dog2 =