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
2
votes
1 answer

JIL json serializer does not serialize properties from derived class

JIL json serializer does not serialize properties from derived class Below are the code snippet: public async Task WriteAsync(OutputFormatterWriteContext context) { if (context == null) { throw new…
Nayan Rudani
  • 1,029
  • 3
  • 12
  • 21
2
votes
1 answer

JSONSerialization.jsonObject returns nil

var responseString = String(data: data, encoding: .utf8) var responseDict: [AnyHashable : Any]? = nil if let anEncoding = responseString?.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue)) { responseDict = try!…
Nitish
  • 13,845
  • 28
  • 135
  • 263
2
votes
1 answer

Support default serialisation for a custom class in a nested type

I defined a class A and I am using objects of A inside other classes, containers and nested types. Example a = A() b = [a,3,'hello' c = {'hey': b, 'huy': 3} d = [a,b,c] I am interested in the json representation of d, so of course I have to specify…
Nisba
  • 3,210
  • 2
  • 27
  • 46
2
votes
1 answer

Keep trailing zeros in bigdecimal in json

I have created onse serializer class which should restrict Bigdecimal to tow digits after decimal. But its removing zeros too. For ex: if value is 95.50, its truncating zero and output as 95.5 in json. public class PriceJsonSerializer extends…
user2160534
  • 97
  • 1
  • 5
  • 12
2
votes
1 answer

Newtonsoft JSON: TypeNameHandling - $type purpose

What is the main purpose (or advantage) of having $type value generated in JSON data? Does it simplify deserialization in some way? I enabled this by setting TypeNameHandling property of (de)serializer, because my intent was to have a strong…
2
votes
2 answers

Json formatting with Json.net in C#

I am trying to parse a bunch of XML files into a single JSON file, which is already working. The final JSON file looks like the following: { "items": [ { "subItems": [ { "Name": "Name", …
SaraFlower
  • 755
  • 1
  • 8
  • 15
2
votes
2 answers

How to prevent Newtonsoft JsonSerializer to close the stream?

So I haven't written the code I'm dealing right now and I'm looking how to best handle this. Right now I have this. public static void WriteSymbol(Stream stream, Symbol symbol) { using (var streamWriter = new StreamWriter(stream)) { …
ditoslav
  • 4,563
  • 10
  • 47
  • 79
2
votes
1 answer

How to pass multiple arguments to a JsonConverter when applied via an attribute?

We are having a web api project and inorder to convert the date time to date and vice versa, we are using DateTimeconverter extended from JsonConverter. We are using this in the form of an attribute for all the required DateTime properties (as shown…
Silly John
  • 1,584
  • 2
  • 16
  • 34
2
votes
2 answers

PHP fatal error: Interface 'JsonSerializable' not found

I have moved and configured my D8 site from Windows to Ubuntu 14.04 PC today. But when I run the site I am getting the following error: Fatal error: Interface 'JsonSerializable' not found in…
Subrata Sarkar
  • 2,975
  • 6
  • 45
  • 85
2
votes
0 answers

PostAsJson could not post data

I have Web api method like below. The Web API is developed inClassic .Net 4.6.2 [HttpPost] public async Task> GetDocuments([FromBody]IEnumerable documentNames) { return await…
LP13
  • 30,567
  • 53
  • 217
  • 400
2
votes
1 answer

Custom JSON serialization for Java datatypes

In MobileFirst Foundation 8.0, are there any hook points to add a custom JSON serialization for Java datatypes in Java adapters? For example: Using a Date object in a pojo class, this gets serialized to a default format "2016-09-27T12:11:17.430Z". I…
2
votes
1 answer

C# ServiceStack JsonSerializer Deserialize

How can I deserialize a string to Json object where the json Object can be a single or an array, right now I have this, which works but its a hack (pseudo): class MyObject{ public string prop1 public string prop2; } class MyList{ …
user1529412
  • 3,616
  • 7
  • 26
  • 42
2
votes
1 answer

JSONTypeInfo to not ignore property in inheritance mapping

I am using following dependency for JSON serialization/deserialization com.fasterxml.jackson.core jackson-databind 2.7.4
Akshay
  • 3,558
  • 4
  • 43
  • 77
2
votes
2 answers

Get all .json Files from a Folder and then serialize in a single .Json File using C# and JSON.Net and Serialize

I have many .json file which I stored in a folder. Now I want to get all these .json files to serialize in a single file. Well I am started how to proceed with it but not getting the correct approach of it. My single .json file look like this- { …
user5850934
2
votes
1 answer

@JsonSerialize not working

In Spring/Hibernate project, in my entity class I have: package klab.finance.main.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import…
Mikhail Batcer
  • 1,938
  • 7
  • 37
  • 57