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; }
}
1836 questions
434
votes
32 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
  • 23,368
  • 41
  • 108
  • 164
184
votes
3 answers

What is deserialize and serialize in JSON?

I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
63
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,408
  • 1
  • 11
  • 15
57
votes
2 answers

Jackson - @JsonTypeInfo property is being mapped as null?

I have this response: { "id":"decaa828741611e58bcffeff819cdc9f", "statement":"question statement", "exercise_type":"QUESTION" } Then, based on exercise_type attribute, I want to instantiate different objects instances (subclasses of…
jscherman
  • 4,789
  • 12
  • 40
  • 80
53
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,309
  • 2
  • 13
  • 24
52
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
  • 4,794
  • 3
  • 30
  • 46
50
votes
6 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
  • 13,048
  • 6
  • 46
  • 58
37
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
  • 6,775
  • 4
  • 49
  • 92
35
votes
3 answers

Deserialize a JSON array in C#

I'm stuck with a tricky problem. I've a JSON string of this format: [{ "record": { "Name": "Komal", "Age": 24, "Location": "Siliguri" } }, { "record": { "Name":…
Arnab Das
  • 2,986
  • 6
  • 25
  • 40
34
votes
8 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,087
  • 3
  • 9
  • 22
34
votes
3 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
  • 463
  • 1
  • 5
  • 12
33
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
  • 45,586
  • 30
  • 89
  • 135
33
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,300
  • 5
  • 26
  • 38
30
votes
1 answer

JSON.NET: How to deserialize interface property based on parent (holder) object value?

I have such classes class Holder { public int ObjType { get; set; } public List Objects { get; set; } } abstract class Base { // ... doesn't matter } class DerivedType1 : Base { // ... doesn't matter } class DerivedType2 :…
Zoka
  • 2,126
  • 4
  • 20
  • 31
29
votes
3 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,355
  • 5
  • 34
  • 57
1
2 3
99 100