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
537
votes
37 answers

Fastest way to check if a string is JSON in PHP?

I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way: function isJson($string) { return ((is_string($string) && (is_object(json_decode($string)) || …
Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177
288
votes
4 answers

What is deserialize and serialize in JSON?

I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
75
votes
2 answers

Jackson - @JsonTypeInfo property is being mapped as null?

Say I have the following JSON: { "id":"decaa828741611e58bcffeff819cdc9f", "statement":"question statement", "exercise_type":"QUESTION" } then, based on the exercise_type field, I want to instantiate different objects instances…
jscherman
  • 5,839
  • 14
  • 46
  • 88
69
votes
5 answers

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING

I have a REST service built with Jersey and deployed in the AppEngine. The REST service implements the verb PUT that consumes an application/json media type. The data binding is performed by Jackson. The verb consumes an enterprise-departments…
Manolo
  • 1,500
  • 1
  • 11
  • 15
64
votes
1 answer

Is Jackson's @JsonSubTypes still necessary for polymorphic deserialization?

I am able to serialize and deserialize a class hierarchy where the abstract base class is annotated with @JsonTypeInfo( use = JsonTypeInfo.Id.MINIMAL_CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") but no @JsonSubTypes…
davidbak
  • 5,775
  • 3
  • 34
  • 50
60
votes
7 answers

Deserializing JSON when sometimes array and sometimes object

I'm having a bit of trouble deserializing data returned from Facebook using the JSON.NET libraries. The JSON returned from just a simple wall post looks like: { "attachment":{"description":""}, …
mfanto
  • 14,168
  • 6
  • 51
  • 61
59
votes
3 answers

Deserializing into a HashMap of custom objects with jackson

I have the following class: import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonProperty; import java.io.Serializable; import java.util.HashMap; @JsonIgnoreProperties(ignoreUnknown = true) public…
wbj
  • 1,429
  • 2
  • 15
  • 25
48
votes
2 answers

Using Gson in Kotlin to parse JSON array

Trying to parse JSON array in Kotlin, made it work for single JSON object to a WeatherObject object (code snippet below) { "coord": { "lon": -2.93, "lat": 43.26 }, "weather": [{ "id": 802, "main": "Clouds", "description":…
lannyf
  • 9,865
  • 12
  • 70
  • 152
48
votes
3 answers

Deserialize a JSON array in C#

I've a JSON string of this format: [{ "record": { "Name": "Komal", "Age": 24, "Location": "Siliguri" } }, { "record": { "Name": "Koena", "Age": 27, …
Arnab Das
  • 3,548
  • 8
  • 31
  • 43
47
votes
10 answers

Swift's JSONDecoder with multiple date formats in a JSON string?

Swift's JSONDecoder offers a dateDecodingStrategy property, which allows us to define how to interpret incoming date strings in accordance with a DateFormatter object. However, I am currently working with an API that returns both date strings…
RamwiseMatt
  • 2,717
  • 3
  • 16
  • 22
39
votes
4 answers

Deserialize json character as enumeration

I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm…
SelAromDotNet
  • 4,715
  • 5
  • 37
  • 59
39
votes
6 answers

Can Jackson polymorphic deserialization be used to serialize to a subtype if a specific field is present?

Using a spin on the zoo example: public class ZooPen { public String type; public List animals; } public class Animal { public String name; public int age; } public class Bird extends Animal { public double…
Shaun
  • 2,490
  • 6
  • 30
  • 39
38
votes
4 answers

Parsing large JSON file in .NET

I have used the "JsonConvert.Deserialize(json)" method of Json.NET so far which worked quite well and to be honest, I didn't need anything more than this. I am working on a background (console) application which constantly downloads the JSON content…
Yavar Hasanov
  • 513
  • 1
  • 6
  • 12
36
votes
4 answers

GSON Case-Insensitive Enum Deserialization

I have an enum: enum Type { LIVE, UPCOMING, REPLAY } And some JSON: { "type": "live" } And a class: class Event { Type type; } When I try to deserialize the JSON, using GSON, I receive null for the Event type field, since the case of…
Steve
  • 53,375
  • 33
  • 96
  • 141
35
votes
8 answers

Deserialization of reference types without parameterless constructor is not supported

I have this API public ActionResult AddDocument([FromBody]AddDocumentRequestModel documentRequestModel) { AddDocumentStatus documentState = _documentService.AddDocument(documentRequestModel, DocumentType.OutgoingPosShipment); …
Yoana Gancheva
  • 529
  • 1
  • 5
  • 10
1
2 3
99 100