Questions tagged [deserialization]

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

7954 questions
92
votes
3 answers

Moshi vs Gson in android

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 android? Does Moshi use reflection also? What are some…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
89
votes
5 answers

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 = @" { 'field1': '123456789012345', …
Vivek Tiwari
  • 961
  • 1
  • 8
  • 7
88
votes
3 answers

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 to choose one of these types over the other?…
Justin R.
  • 23,435
  • 23
  • 108
  • 157
80
votes
8 answers

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

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. Here is a simple example: public…
AndyDBell
  • 968
  • 1
  • 7
  • 10
77
votes
3 answers

serialize and deserialize enum with Gson

How can i serialize and deserialize a simple enum like this with gson 2.2.4 ? public enum Color { RED, BLUE, YELLOW; }
user2183448
  • 783
  • 1
  • 5
  • 7
75
votes
3 answers

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 { "Id": "123", "Enabled": true, "Age": 23 } I want…
Mando
  • 11,414
  • 17
  • 86
  • 167
74
votes
2 answers

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 check that o is string and equals…
liuhongbo
  • 2,051
  • 4
  • 22
  • 29
70
votes
5 answers

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

I have a domain object that has a Map: private Map> autoHandling; When I serialize the object, I get this: "autoHandling" : [ "java.util.HashMap", { } ], This Map's key is a custom Object: public…
Mick Knutson
  • 2,297
  • 3
  • 25
  • 48
69
votes
7 answers

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(strJSONData) to take data from a web request and convert it to a class object (I can change the class). By decorating my class properties with…
David P
  • 2,027
  • 3
  • 15
  • 27
69
votes
6 answers

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{ public List posts; } And Deserialization call is: public class JsonDownloader
VizGhar
  • 3,036
  • 1
  • 25
  • 38
69
votes
2 answers

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 can add the XmlIgnore attribute: [XmlIgnore] public…
Manoj
  • 1,005
  • 1
  • 9
  • 11
67
votes
1 answer

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
  • 19,844
  • 33
  • 126
  • 242
66
votes
7 answers

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? ) @JsonInclude(JsonInclude.Include.NON_NULL) data class…
Mike
  • 725
  • 1
  • 8
  • 11
66
votes
4 answers

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 way because, most part of properties are values,…
gc5
  • 9,468
  • 24
  • 90
  • 151
65
votes
9 answers

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":"bob@email.com"} to a Java Person instance using Person bob =…
spg
  • 9,309
  • 4
  • 36
  • 41