Questions tagged [json-deserialization]

JSON deserialization is the process of converting a JSON string into an instance of an object, often a class.

JSON (Object Notation) is an efficient data encoding format that enables fast exchanges of small amounts of data between client browsers and -enabled Web services.

JSON deserialization is the process of converting a JSON string into an instance of an object, often a class. JSON encoded strings carry both structural and data information, so the instance of the object resulting from deserialization is a well-defined, data-filled object.

For example the following string:

string json_encoded_string = @"{""name"" : ""John"", ""surname"" : ""Doe"", ""age"" : 38}";

can be deserialized into an instance of the following class:

class Person
{
    public string name { get; set; }
    public string surname { get; set; }
    public int age { get; set; }
}
2322 questions
17
votes
5 answers

How to iterate a JsonObject (gson)

I have a JsonObject e.g JsonObject jsonObject = {"keyInt":2,"keyString":"val1","id":"0123456"} Every JsonObject contains a "id" entry, but the number of other key/value pairs is NOT determined, so I want to create create an object with 2…
Floyd
  • 391
  • 1
  • 3
  • 10
17
votes
1 answer

How to load JSON data into nested classes?

I have JSON data as follows: { "Address": { "House_Number": 2, "State": "MA", "Street_Number": 13 }, "Name": "John" } I want to load it into a class defined as follows: class Address: def __init__(self): …
Chandrahas
  • 325
  • 4
  • 14
17
votes
2 answers

Jackson deserialization convertValue vs readValue

I have a org.json.JSONArray that contains JSONObjects and I am trying to map those to a POJO. I know the type of the POJO I want to map to. I have 2 options and I m trying to figure out which is better in performance. Option 1: ObjectMapper mapper =…
bsam
  • 1,838
  • 3
  • 20
  • 26
15
votes
4 answers

Parse JSON into anonymous object[] using JSON.net

I have a json string that I want to parse into an object[]: { "Thing":"Thing","That":{"Item1":15,"Item2":"Moo","Item3":{"Count":27,"Type":"Frog"}}} The resulting anonymous object array needs to contain each of the properties of the original json…
Ritz
  • 203
  • 1
  • 2
  • 10
14
votes
2 answers

Spring Kafka JsonDesirialization MessageConversionException failed to resolve class name Class not found

I have two services that should communicate via Kafka. Let's call the first service WriteService and the second service QueryService. On the WriteService side, I have the following configuration for producers. @Configuration public class…
CROSP
  • 4,499
  • 4
  • 38
  • 89
14
votes
4 answers

How to deserialise a subclass in Firebase using getValue(Subclass.class)

I'm using the new firebase sdk for android and use the real database feature. When i use the getValue(simple.class) everything is fine. But when i want to parse a class which is a subclass, all the attribute of the mother class are null, and i have…
13
votes
2 answers

Deserialize file using serde_json at compile time

At the beginning of my program, I read data from a file: let file = std::fs::File::open("data/games.json").unwrap(); let data: Games = serde_json::from_reader(file).unwrap(); I would like to know how it would be possible to do this at compile time…
Nils André
  • 571
  • 5
  • 17
13
votes
3 answers

Deserialize complex JSON to Java, classes nested multiple levels deep

I am trying to make the Json output from Cucumber into a single Java object. This contains objects nested four levels deep, and I am having trouble deserializing it. I am presently using Jackson, but open to suggestions. Here is my Json…
KeizerHarm
  • 330
  • 1
  • 4
  • 22
13
votes
2 answers

Relations and differences between marshall/unmarshal, encoding/decoding, and serialization/deserialization for JSON?

In Go's JSON package, I saw there are marshal, decode and other functions. I thought that decode is the opposite to marshal, but latter realized that I might be wrong. I think the fundamental question that I have is: What are the relations and…
Tim
  • 1
  • 141
  • 372
  • 590
13
votes
4 answers

How to handle different data types with same attribute name with Gson?

I'm currently writing an RSS feed parser in Java utilizing Gson. I'm converting the RSS' XML into JSON, and then subsequently using Gson to deserialize the JSON into Java POJOs (somewhat roundabout but there's a reason for it). Everything was…
Steve Pierce
  • 322
  • 2
  • 9
13
votes
1 answer

PHP json_decode return error code 4

I had previously asked the same question. I would like to decode the json from: http://pad.skyozora.com/data/pets.json. Below is the code I used…
Patrick Ng
  • 203
  • 1
  • 4
  • 13
13
votes
2 answers

JSON string to Java object with Jackson

This is probably one of those questions where the title says it all. I am quite fascinated by the ObjectMapper's readValue(file, class) method, found within the Jackson library which reads a JSON string from a file and assigns it to an object. I'm…
ViRALiC
  • 1,419
  • 4
  • 18
  • 46
13
votes
2 answers

RestSharp JSON Array deserialization

I launch this RestSharp query in JSON format: var response = restClient.Execute(request); The response I get contains this data [ { "Columns": [ {"Name":"CameraGuid","Type":"Guid"}, …
BriocheBro
  • 165
  • 1
  • 1
  • 5
12
votes
6 answers

Kotlinx Serialization - Custom serializer to ignore null value

Let's say I'm having a class like: @Serializable data class MyClass( @SerialName("a") val a: String?, @SerialName("b") val b: String ) Assume the a is null and b's value is "b value", then Json.stringify(MyClass.serializer(), this)…
12
votes
2 answers

Custom deserializer only for some fields with json.NET

I'm trying to deserialize some JSON: { "a":1, "b":25, "c":"1-7", "obj1":{ "a1":10, "b1":45, "c1":60 }, "obj2":[ { "a2":100, "b2":15, "c2":50 }, { …
dyesdyes
  • 1,147
  • 3
  • 24
  • 39