Questions tagged [deserialization]

Deserialization is the process by which an object is recreated from its serialized state.

deserialization
Filter by
Sorted by
Tagged with
560 votes
18 answers
1.5m views

How can I deserialize JSON with C#?

I have the following code: var user = (Dictionary<string, object>)serializer.DeserializeObject(responsecontent); The input in responsecontent is JSON, but it is not properly deserialized into ...
user avatar
464 votes
17 answers
1.4m views

Convert string with commas to array

How can I convert a string to a JavaScript array? Look at the code: var string = "0,1"; var array = [string]; alert(array[0]); In this case alert shows 0,1. If it where an array, it would ...
Scott's user avatar
  • 6,121
369 votes
6 answers
353k views

.NET NewtonSoft JSON deserialize map to a different property name

I have following JSON string which is received from an external party. { "team":[ { "v1":"", "attributes":{ "eighty_min_score":"", "home_or_away":"...
RasikaSam's user avatar
  • 5,473
343 votes
12 answers
748k views

Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)

I know there are a few posts about Newtonsoft so hopefully this isn't exactly a repeat...I'm trying to convert JSON data returned by Kazaa's API into a nice object of some kind WebClient client = new ...
J Benjamin's user avatar
  • 4,752
340 votes
9 answers
382k views

How to implement custom JsonConverter in JSON.NET?

I am trying to extend the JSON.net example given here http://james.newtonking.com/projects/json/help/CustomCreationConverter.html I have another sub class deriving from base class/Interface public ...
Snakebyte's user avatar
  • 3,775
313 votes
9 answers
461k views

Storing Python dictionaries

Are there simple ways to store a dictionary (or multiple dictionaries) in, for example, a JSON or pickle file? For example, if I have some data like: data = {} data ['key1'] = "keyinfo" data ...
mike's user avatar
  • 23.3k
301 votes
8 answers
419k views

Deserializing a JSON into a JavaScript object

I have a string in a Java server application that is accessed using AJAX. It looks something like the following: var json = [{ "adjacencies": [ { "nodeTo": "graphnode2", ...
mj_'s user avatar
  • 6,357
300 votes
4 answers
439k views

What is deserialize and serialize in JSON?

I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
coderex's user avatar
  • 27.5k
270 votes
9 answers
542k views

Converting Stream to String and back

I want to serialize objects to strings, and back. We use protobuf-net to turn an object into a Stream and back, successfully. However, Stream to string and back... not so successful. After going ...
flipuhdelphia's user avatar
158 votes
6 answers
82k views

Performant Entity Serialization: BSON vs MessagePack (vs JSON)

Recently I've found MessagePack, an alternative binary serialization format to Google's Protocol Buffers and JSON which also outperforms both. Also there's the BSON serialization format that is used ...
Alex's user avatar
  • 8,335
147 votes
5 answers
380k views

Deserializing JSON data to C# using JSON.NET

I'm relatively new to working with C# and JSON data and am seeking guidance. I'm using C# 3.0, with .NET3.5SP1, and JSON.NET 3.5r6. I have a defined C# class that I need to populate from a JSON ...
user avatar
121 votes
5 answers
133k views

JSON to TypeScript class instance? [duplicate]

I've done quite some research, but I'm not totally satisfied with what I found. Just to be sure here's my question: What is actually the most robust and elegant automated solution for deserializing ...
Klaus's user avatar
  • 1,211
119 votes
13 answers
79k views

How to remove k__BackingField from json when Deserialize

I am getting the k_BackingField in my returned json after serializing a xml file to a .net c# object. I've added the DataContract and the DataMember attribute to the .net c# object but then I get ...
Filling The Stack is What I DO's user avatar
114 votes
9 answers
66k views

Polymorphism with gson

I have a problem deserializing a json string with Gson. I receive an array of commands. The command can be start, stop , some other type of command. Naturally I have polymorphism, and start/stop ...
Sophie's user avatar
  • 1,580
102 votes
4 answers
332k views

Newtonsoft JSON Deserialize

My JSON is as follows: {"t":"1339886","a":true,"data":[],"Type":[['Ants','Biz','Tro']]} I found the Newtonsoft JSON.NET deserialize library for C#. I tried to use it as follow: object JsonDe = ...
abc cba's user avatar
  • 2,593
97 votes
9 answers
165k views

Fastest way to serialize and deserialize .NET objects

I'm looking for the fastest way to serialize and deserialize .NET objects. Here is what I have so far: public class TD { public List<CT> CTs { get; set; } public List<TE> TEs { ...
aron's user avatar
  • 1,904
94 votes
6 answers
72k views

multiple JsonProperty Name assigned to single property

I have two format of JSON which I want to Deserialize to one class. I know we can't apply two [JsonProperty] attribute to one property. Can you please suggest me a way to achieve this? string json1 =...
Vivek Tiwari's user avatar
  • 1,021
92 votes
3 answers
36k views

Moshi vs Gson in android [closed]

I'm deciding on whether to use Moshi by square or Gson to serialize and deserialize model data. one thing i always did not like about Gson is i think it uses reflection which can be slow on ...
j2emanue's user avatar
  • 61.7k
88 votes
3 answers
36k views

What's the difference between DataContractJsonSerializer and JavaScriptSerializer?

The .NET Framework ships with System.Runtime.Serialization.Json.DataContractJsonSerializer and System.Web.Script.Serialization.JavaScriptSerializer, both of which de/serialize JSON. How do I know when ...
Justin R.'s user avatar
  • 23.7k
81 votes
8 answers
311k views

NewtonSoft.Json Serialize and Deserialize class with property of type IEnumerable<ISomeInterface>

I am trying to move some code to consume ASP.NET MVC Web API generated Json data instead of SOAP Xml. I have run into a problem with serializing and deserializing properties of type: IEnumerable<...
AndyDBell's user avatar
  • 978
79 votes
3 answers
78k views

serialize and deserialize enum with Gson [duplicate]

How can i serialize and deserialize a simple enum like this with gson 2.2.4 ? public enum Color { RED, BLUE, YELLOW; }
user2183448's user avatar
77 votes
3 answers
54k views

Ignore parsing errors during JSON.NET data parsing

I have an object with predefined data structure: public class A { public string Id {get;set;} public bool? Enabled {get;set;} public int? Age {get;set;} } and JSON is supposed to be { "...
Mando's user avatar
  • 11.6k
77 votes
2 answers
30k views

Json.NET Disable the deserialization on DateTime

Here is the code: string s = "2012-08-08T01:54:45.3042880+00:00"; JObject j1 = JObject.FromObject(new { time=s }); Object o = j1["time"]; We can ...
liuhongbo's user avatar
  • 2,111
76 votes
5 answers
83k views

Can not find a (Map) Key deserializer for type [simple type, class ...]

I have a domain object that has a Map: private Map<AutoHandlingSlotKey, LinkedHashSet<AutoFunction>> autoHandling; When I serialize the object, I get this: "autoHandling" : [ &...
Mick Knutson's user avatar
  • 2,377
71 votes
1 answer
25k views

Is json.loads() vulnerable to arbitrary code execution?

Is json.loads from Python's standard json module vulnerable to arbitrary code execution or any other security problems? My application can receive JSON messages from non-trustworthy sources.
FrozenHeart's user avatar
  • 20.3k
70 votes
7 answers
107k views

Deserializing Generic Types with GSON

I have some problems with implementation of Json Deserialization in my Android application (with Gson library) I've made class like this public class MyJson<T>{ public List<T> posts; ...
VizGhar's user avatar
  • 3,086
70 votes
2 answers
71k views

Ignore a property during xml serialization but not during deserialization

In C#, how can I make XmlSerializer ignore a property during serialization but not during deserialization? (Or how do I do the same with Json.net?) To prevent a property from being serialized, you ...
Manoj's user avatar
  • 1,015
69 votes
7 answers
43k views

Can I specify a path in an attribute to map a property in my class to a child property in my JSON?

There is some code (which I can't change) that uses Newtonsoft.Json's DeserializeObject<T>(strJSONData) to take data from a web request and convert it to a class object (I can change the class). ...
David P's user avatar
  • 2,027
68 votes
8 answers
75k views

Usage of Jackson @JsonProperty annotation for kotlin data classes

kotlin 1.2.10 jackson-module-kotlin:2.9.0 I have the following data class in kotlin: data class CurrencyInfo( @JsonProperty("currency_info") var currencyInfo: CurrencyInfoItem? ) @...
Mike's user avatar
  • 755
67 votes
9 answers
64k views

REST Assured - Generic List deserialization

Let's say I have a Java Person class: class Person { String name; String email; } With REST Assured, you can deserialize this JSON object {"name":"Bob", "email":"[email protected]"} to a Java ...
spg's user avatar
  • 9,559
66 votes
4 answers
149k views

Right way to write JSON deserializer in Spring or extend it

I am trying to write a custom JSON deserializer in Spring. I want to use default serializer for most part of fields and use a custom deserializer for few properties. Is it possible? I am trying this ...
gc5's user avatar
  • 9,668
66 votes
10 answers
188k views

java.io.InvalidClassException: local class incompatible:

I created client and server and then added a class in client side for serializing purposes, then simply just went to the folder of the client in my hard drive and copy paste it to the server ...
lonesome's user avatar
  • 2,524
65 votes
4 answers
149k views

Java serialization - java.io.InvalidClassException local class incompatible [duplicate]

I've got a public class, which implements Serializable, that is extended by multiple other classes. Only those subclasses were ever serialized before - never the super class. The super class had ...
Dale's user avatar
  • 3,557
64 votes
3 answers
164k views

How to load a JSON file and convert it to an object of a specific type?

I have a type FooObject and I have a JSON file which was serialized from a FooObject instance. Now I want to use ConvertFrom-Json to load the JSON file to memory and covert the output of the command ...
NonStatic's user avatar
  • 1,021
64 votes
1 answer
88k views

What are @JsonTypeInfo and @JsonSubTypes used for in jackson

What are the @JsonTypeInfo and @JsonSubTypes annotations used for in Jackson? public class Lion extends Animal { private String name; @JsonCreator public Lion(@JsonProperty("name") String ...
Harshit's user avatar
  • 1,194
63 votes
8 answers
62k views

Deserializing polymorphic types with Jackson based on the presence of a unique property

If I have a class structure like so: public abstract class Parent { private Long id; ... } public class SubClassA extends Parent { private String stringA; private Integer intA; ......
Sam Berry's user avatar
  • 7,554
62 votes
5 answers
30k views

What's the Jackson deserialization equivalent of @JsonUnwrapped?

Say I have the following class: public class Parent { public int age; @JsonUnwrapped public Name name; } Producing JSON: { "age" : 18, "first" : "Joey", &...
Shaun's user avatar
  • 2,510
58 votes
8 answers
63k views

How to handle a NumberFormatException with Gson in deserialization a JSON response

I'm reading a JSON response with Gson, which returns somtimes a NumberFormatException because an expected int value is set to an empty string. Now I'm wondering what's the best way to handle this kind ...
Soundlink's user avatar
  • 3,931
58 votes
3 answers
72k views

Polymorphism in jackson annotations: @JsonTypeInfo usage

I would like to know if @JsonTypeInfo annotation can be used for interfaces. I have set of classes which should be serialized and deserialized. Here is what I'm trying to do. I have two ...
Chris's user avatar
  • 5,614
57 votes
3 answers
93k views

How do I write a custom JSON deserializer for Gson?

I have a Java class, User: public class User { int id; String name; Timestamp updateDate; } And I receive a JSON list containing user objects from a webservice: [{"id":1,"name":"Jonas","...
Jonas's user avatar
  • 125k
57 votes
5 answers
150k views

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type

I have a class like this: public class MyStok { public int STId { get; set; } public int SM { get; set; } public string CA { get; set; } public string Br { get; set; } public ...
sakir's user avatar
  • 3,441
57 votes
5 answers
36k views

How do I use JSON.NET to deserialize into nested/recursive Dictionary and List?

I need to deserialize a complex JSON blob into standard .NET containers for use in code that is not aware of JSON. It expects things to be in standard .NET types, specifically Dictionary<string, ...
dongryphon's user avatar
57 votes
3 answers
29k views

Why my exception class needs to be serialized?

When you extend a class with class Exception ( for creating new exception) you get a warning to have a serialVersionUID. I know that serialVersionUID plays an important role while serialization and ...
amod's user avatar
  • 4,220
57 votes
4 answers
192k views

Serializing/deserializing with memory stream

I'm having an issue with serializing using memory stream. Here is my code: /// <summary> /// serializes the given object into memory stream /// </summary> /// <param name="objectType"&...
gng's user avatar
  • 715
55 votes
3 answers
111k views

Error Deserializing Xml to Object - xmlns='' was not expected

I am having real trouble trying to deserialize some XML and was hoping someone can offer some assistance. I have read a lot of similar posts but I am unable to resolve this. XML I am attempting to ...
ProNotion's user avatar
  • 3,682
54 votes
7 answers
25k views

Deserialize JSON into existing object (Java)

I'd like to know how one might get the Jackson JSON library to deserialize JSON into an existing object? I've tried to find how to to this; but it seems to only be able to take a Class and instantiate ...
Jonas N's user avatar
  • 1,757
52 votes
1 answer
23k views

Convert an int to bool with Json.Net [duplicate]

I am calling a webservice and the returned data for a bool field is either 0 or 1 however with my model I am using a System.Bool With Json.Net is it possible to cast the 0/1 into a bool for my model? ...
Diver Dan's user avatar
  • 9,963
50 votes
1 answer
19k views

Jackson deserialize extra fields as Map

I'm looking to deserialize any unknown fields in a JSON object as entries in a Map which is a member of a POJO. For example, here is the JSON: { "knownField" : 5, "unknownField1&...
kag0's user avatar
  • 5,814
50 votes
3 answers
208k views

Deserialize a JSON array in C#

I've a JSON string of this format: [{ "record": { "Name": "Komal", "Age": 24, "Location": "...
Arnab Das's user avatar
  • 3,638
50 votes
2 answers
11k views

What is the use of @Serial annotation as of Java 14

Java 14 introduces a new annotation @Serial in the java.io package. Its brief description in the API docs: Indicates that an annotated field or method is part of the serialization mechanism defined ...
Nikolas Charalambidis's user avatar

1
2 3 4 5
162