Questions tagged [deserialization]
Deserialization is the process by which an object is recreated from its serialized state.
deserialization
8,083
questions
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 ...
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 ...
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":"...
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 ...
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 ...
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 ...
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",
...
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?
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 = ...
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 { ...
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 =...
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 ...
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 ...
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<...
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;
}
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
{ "...
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 ...
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" : [ &...
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.
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;
...
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 ...
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). ...
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?
)
@...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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;
......
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",
&...
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 ...
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 ...
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","...
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 ...
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, ...
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 ...
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"&...
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 ...
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 ...
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?
...
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&...
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": "...
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 ...