Questions tagged [jsonserializer]

The JsonSerializer enables to control how objects are encoded into JSON. JSONSerializer will also pay attention to any method or field annotated by JSON.

JSONSerializer is the main class for performing serialization of Java objects to JSON. JSONSerializer by default performs a shallow serialization. While this might seem strange there is a method to this madness. Shallow serialization allows the developer to control what is serialized out of the object graph. This helps with performance, but more importantly makes good OO possible, fixes the circular reference problem, and doesn't require boiler plate translation code.

A simple example:

JSONSerializer serializer = new JSONSerializer();
return serializer.serialize( person );

Source:

Related tags:

512 questions
307
votes
12 answers

Cannot find JavaScriptSerializer in .Net 4.0

I cannot seem to find the JavaScriptSerializer object nor the the System.Web.Script.Serialization namespace within Visual Studio 2010. I need to serialize something to JSON what am I supposed to use? And yes, I already included the…
Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137
283
votes
19 answers

Jackson enum Serializing and DeSerializer

I'm using JAVA 1.6 and Jackson 1.9.9 I've got an enum public enum Event { FORGOT_PASSWORD("forgot password"); private final String value; private Event(final String description) { this.value = description; } …
pookieman
  • 2,981
  • 2
  • 14
  • 8
191
votes
8 answers

Serializing object that contains cyclic object value

I have an object (parse tree) that contains child nodes which are references to other nodes. I'd like to serialize this object, using JSON.stringify(), but I get TypeError: cyclic object value because of the constructs I mentioned. How could I…
Loic Duros
  • 5,472
  • 10
  • 43
  • 56
108
votes
5 answers

JObject.Parse vs JsonConvert.DeserializeObject

What's the difference between JsonConvert.DeserializeObject and JObject.Parse? As far as I can tell, both take a string and are in the Json.NET library. What kind of situation would make one more convenient than the other, or is it mainly just…
hubatish
  • 5,070
  • 6
  • 35
  • 47
75
votes
12 answers

Ruby objects and JSON serialization (without Rails)

I'm trying to understand the JSON serialization landscape in Ruby. I'm new to Ruby. Is there any good JSON serialization options if you are not working with Rails? That seems to be where this answer goes (to Rails) How to convert a Ruby object to…
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
71
votes
4 answers

Does .NET 4 have a built-in JSON serializer/deserializer?

Does .NET 4 come with any class that serializes/deserializes JSON data? I know there are 3rd-party libraries, such as JSON.NET, but I am looking for something built right into .NET. I found Data Contracts on MSDN, but it is for WCF, not for…
Cheung
  • 15,293
  • 19
  • 63
  • 93
47
votes
8 answers

error CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web'

I am trying to use JavaScriptSerializer in my application. I initially received Cannot find JavaScriptSerializer and I solved it by adding: using System.Web.Script.Serialization; But then the sub-keyword Script is underlined with a blue…
scatmoi
  • 1,958
  • 4
  • 18
  • 32
41
votes
4 answers

pydantic convert to jsonable dict (not full json string)

I'd like to use pydantic for handling data (bidirectionally) between an api and datastore due to it's nice support for several types I care about that are not natively json-serializable. It has better read/validation support than the current…
some bits flipped
  • 2,592
  • 4
  • 27
  • 42
39
votes
3 answers

JavaScriptSerializer is not allowed in .net core project?

I am working in .net core project. I want to serialize the objects using JavaScriptSerializer. JavaScriptSerializer Serializer = new JavaScriptSerializer(); I added the namespace using System.Web.Script.Serialization;. It throws errors. I googled…
22
votes
3 answers

JsonSerializer - serialize decimal places with 'N2' formatting

I'm serializing decimals using Newtonsoft.Json.JsonSerializer. How can I set it to serialize decimal numbers with only 1 decimal place to use 0 at the end. i.e. 3.5 serializes to "3.50"?
Chris
  • 7,996
  • 11
  • 66
  • 98
20
votes
4 answers

.net core GraphQL, GraphQL.SystemTextJson: Serialization and deserialization of 'System.Type' instances are not supported

In a ASP.NET core 5 application, I use GraphQL with GraphQL.SystemTextJson. When I attempt to return a result, I get s System.NotSupportedException saying "Serialization and deserialization of 'System.Type' instances are not supported and should be…
Starnuto di topo
  • 3,215
  • 5
  • 32
  • 66
17
votes
1 answer

Each parameter in the deserialization constructor on type must bind to an object property or field on deserialization

I have the following simple classes : public abstract class GitObject { public Repository Repository { get; set; } public abstract string Serialize(); public abstract void Deserialize(string data); public class Blob : GitObject …
kklaw
  • 452
  • 2
  • 4
  • 14
17
votes
1 answer

SignalR 2.0 change Json Serializer to support derived type objects

Please note that I'm explicitly referencing SignalR 2.0 here ... I've seen some (nasty) approaches for this with SignalR 1.1/1.2 ... but none for 2.0 yet. Has anyone had any success with changing the SignalR 2.0 default json serializer to enable the…
typhoid
  • 315
  • 5
  • 13
15
votes
4 answers

Rename response fields django rest framework serializer

I'm calling a simple get API using djangorestframework. My Model is class Category(models.Model): category_id = models.AutoField(primary_key=True) category_name = models.CharField("Category Name", max_length = 30) category_created_date…
Pinank Lakhani
  • 1,109
  • 2
  • 11
  • 31
15
votes
5 answers

How can I "un-JsonIgnore" an attribute in a derived class?

I am using Newtonsoft's JsonSerializer to serialise some classes. As I wanted to omit one field of my class in the serialisation process, I declared it as follow: [JsonIgnore] public int ParentId { get; set; } This worked, but I am now facing a new…
PLNech
  • 3,087
  • 1
  • 23
  • 52
1
2 3
34 35