json-deserialization

How to deserialize a scala tree with JSON4S

跟風遠走 提交于 2019-12-25 00:23:10
问题 Serialization works fine but I have nothing for deserialization. I found interesting solution for abstract class here How to serialize sealed abstract class with Json4s in Scala? but it doesn't deal with trees. This the code of my test with a standard JSON4S : import org.json4s._ import org.json4s.native.JsonMethods._ import org.json4s.native.Serialization.{ read, write } import org.json4s.native.Serialization abstract class Tree case class Node(nameN: String, trees: List[Tree]) extends Tree

A Better XElement to Object Without XMLAttributes in C#

落花浮王杯 提交于 2019-12-24 21:05:28
问题 Given an XElement input: <?xml version="1.0"?> <Item Number="100" ItemName="TestName1" ItemId="1"/> with an Item model like: public class Item { public int ItemId { get; set; } public string ItemName { get; set; } public int? Number { get; set; } // public DateTime? Created {get; set;} } Why does this code: public static T DeserializeObject<T>(XElement element) where T : class, new() { try { var serializer = new XmlSerializer(typeof(T)); var x = (T)serializer.Deserialize(element.CreateReader(

JavaRX Pagination - observe in each interration rather than at the end - Generic Paginator

≡放荡痞女 提交于 2019-12-24 19:08:23
问题 I'm working with a paginated API. I have used the following solution provided by Adam Millerchip and it works well. import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.function.Function; import io.reactivex.Flowable; import io.reactivex.Single; import io.reactivex.processors.BehaviorProcessor; public class Pagination { // Fetch all pages and return the items contained in those pages, using the provided page fetcher function

A variable of two types

。_饼干妹妹 提交于 2019-12-24 14:07:04
问题 I need to read an JSON object from TypeScript, which has a variable names prop which of two types, either Identifier or Expression to C#. TypeScript can have a variable with multiple types (with its union type feature), e.g., prop is defined as var property:Identifier | Expression I am reading the JSON object string from C# with JsonConvert.DeserializeObject , e.g., Object facebookFriends = new JavaScriptSerializer().Deserialize<Object>(JSON_Object); How should I declare a variable of two

“Relaxed” fields names for Jackson

左心房为你撑大大i 提交于 2019-12-24 07:15:08
问题 I'm working on Jackson configuration and I wonder if there is any option to deserialise different kinds of field patterns. For example, I have an object: class DeserializeIt { String fieldOne; String fieldOneAndHalf; String fieldTwo; String fieldThree; String fieldFour; //getters setters etc. } And I have below JSON payload: { "fieldOne" : "value1", "field_ONE-and_Half": "value15", "FIELD_TWO": "value2", "FIELD_THREE" : "value3", "field_four": "value4" } I would like to deserialize all these

Need to convert(Deserialize) following json into C# object

心不动则不痛 提交于 2019-12-24 06:47:12
问题 How to convert(deserialize) following json format in C# object? All this json text convert(deserialize) in one go or I need to convert child object again and again I am trying something like this var x = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(json_data); { "Id":"1405de4d-2823-43b4-8dba-66c2714bc7f", "Name":"Sports/Boxing", "Parent":{ "Id":"88ada251-cff1-4eb7-bc47-2e6d366616a63", "Name":"http://localhost:80/PDC/Sports/Boxing", "DurationMilliseconds":227.2,

Flatten JSON based on an attribute - python

ε祈祈猫儿з 提交于 2019-12-24 05:46:35
问题 I have a json array like this: [ { 'id': 1, 'values': [ { 'cat_key': 'ck1' }, { 'cat_key': 'ck2' } ] }, { 'id': 2, 'values': [ { 'cat_key': ck3 } ] } ] I want to flatten this array on the field values such that: [ { 'id': 1, 'cat_key': 'ck1' }, { 'id': 1, 'cat_key': 'ck2' }, { 'id': 2, 'cat_key': 'ck3' } ] What is the most efficient way to do this in python? 回答1: obj = json.loads(json_array) new_obj = [] for d in obj: if d.get('values'): for value in d['values']: new_obj.append(dict(id=d['id'

Deserialize array of objects inside another object using Gson

寵の児 提交于 2019-12-24 03:05:35
问题 Using Volley in my Android project, I am getting a json response like: { "value1": 1, "value2": aaa, "subvalues": [ { "value1": 297, "value2": 310, "class3": { "name": "name1", "id": 1, "value": 32 } }, ... ] } I need to deserialize it to pojo using Gson. Classes are: class1: public class class1 { private int value1; private String value2; private List<class2> vals; public class class2 { private int value1; private int value2; private class3 c3; } } class3: public class class3 { private

json.net custom jobject deserialization

旧城冷巷雨未停 提交于 2019-12-24 01:53:57
问题 I'm trying to use JsonConvert.DeserializeObject(string) to deserialize a string into an jobject that can use with dynamic to access the json document on the fly. However I want to avoid knowing the casing of the document so I can type dynamic document = JsonConvert.DeserializeObject(someString); Console.WriteLine(document.some.path.here.name); and have it work on {"Some":{"path":{"HERE":{"Name":"test"}}} I can't find out how to create a custom class for json.net that will do that for me,

Kafka Deserialize Nested Generic Types

☆樱花仙子☆ 提交于 2019-12-23 18:33:57
问题 Given a class like this public class Message<T> implements Serializable { final String correlationId; final LocalDateTime timestamp; final T payload } How to implement a custom Kafka deserializer that can handle the nested generic type? Serialization should be pretty straight forward, as the type information will be available. But how to handle not having the type information when deserialising? p.s: I am using jackson to do the serialization / deserialization. 回答1: solved by getting jackson