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

Serializing scalar JSON in Flutter's Ferry Graphql for flexible Query

I have the following JSON scalar: """ The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf). """ scalar JSON which I am trying to convert since my query…
Jenny Kim
  • 1,505
  • 2
  • 16
  • 25
2
votes
1 answer

Resolve cycle references of complex type during JSON serialization using System.Text.Json.Serialization.JsonConverter

There is a complex type with a reference to the object of the same type (sometimes to the same object): public class User { public string Name { get; set; } public int Age { get; set; } public User Reference { get; set; } } There is a…
2
votes
2 answers

(de)Serializing stream using System.Text.Json

I am trying to serialize an object into a MemoryStream using System.Text.Json's JsonSerializer. I am unable to find the implementation/method of that in the documentation. Can someone share the sample implementation for serialization and…
user6656240
2
votes
1 answer

How to covert Json result into string in Blazor WebAssembly?

I want to convert the result into a string and pass it to the navigation path, but I couldn't do it, please help me. HttpGet Controller [HttpGet] [Route("UserId")] public async Task> GetUserId(string Username) { var…
2
votes
1 answer

toJson not working properly json serializer Unhandled Exception: Invalid argument: Instance of 'DietModel'

I am trying to save data on firestore but getting error while saving in toJson. i have created two models diet-model and TargetModel to store on firestore using json_serializable: ^4.0.0 and json_annotation: ^4.0.0 . TargetModel have List of…
Lalit Rawat
  • 1,022
  • 2
  • 17
  • 39
2
votes
1 answer

additional attributes in both JSON and XML

I am currently trying to incorporate attributes in the API of my Rails app. The use case is simple. I have a User model: class User < ActiveRecord::Base attr_accessible :email end I have another model, basically linking the users to an…
2
votes
1 answer

Cosmos DB Serialization Issue Throws Error Reading An Int as Double

On some of my documents my .NET Cosmos Db client (v3) will not read a document(s). The document has a property DistanceInMetres and is set to an int on my class. public int DistanceInMetres { get; set; } When I examine one of the documents…
Paul Stanley
  • 1,999
  • 1
  • 22
  • 60
2
votes
1 answer

Jackson: Multiple Serializers on the same entity when differents Rest EndPoint are called

I'm trying to avoid using the DTO antipattern when different EndPoint are called, where each returns a distinct representation of the same entity. I'd like to take advantage of the serialization that Jackson performs when I return the entity in the…
ByteBat
  • 337
  • 4
  • 14
2
votes
2 answers

JsonSerializer.Deserialize can't inferred the usage

if I pass a string just to the method, the VS2019 give error that the usage can't be inferred. if I write like this JsonSerializer.Deserialize(text); JsonSerializer.Deserialize(text.AsSpan()); both are giving the same error. as a string is…
Mohammad Hossein Amri
  • 1,842
  • 2
  • 23
  • 43
2
votes
3 answers

How to remove null values generated by a jackson custom serializer?

Given the following class: @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Account { [... A lot of serialized properties] @JsonSerialize(nullsUsing = JacksonSpringSpelSerializer.class, using = JacksonSpringSpelSerializer.class) …
anthofo
  • 93
  • 12
2
votes
1 answer

Sequel JsonSerializer conflicts with aliasing

In a Sinatra web application I am trying to get data from DB and convert them into object that is acceptable for UI (and finally to JSON). But there is some difference in names of attributes needed for UI and DB fields. So I have used Sequel query…
Andriy Tkach
  • 1,471
  • 2
  • 12
  • 19
2
votes
1 answer

Ignore a Key with JSON encode

How can I ignore a key when using json.encode? Something like this: final map = json.decode(json.encode(routine), reviver: (key, value) { if (key == "id") { return null; } return value; }); But this way my map has a…
Jonas
  • 7,089
  • 15
  • 49
  • 110
2
votes
2 answers

VB.NET converting Object to JSON

I am creating a web request of type POST but the converted JSON is not in the correct format. Below is my function: Public Function CreateWebRequestPOST(ByVal strURL As String, objInput As Object) As JArray Try 'Serialize the…
Rami Zebian
  • 539
  • 1
  • 5
  • 23
2
votes
2 answers

How to avoid collection modification during JSON serialization in looped multithreaded task?

I have a problem during serialization to JSON file, when using Newtonsoft.Json. In a loop I am fiering tasks in various threads: List jockeysTasks = new List(); for (int i = 1; i < 1100; i++) { …
bakunet
  • 197
  • 1
  • 12
2
votes
1 answer

Gson Serialization of Map subclass that also has explicitly-defined properties

I have a collection of generated java beans where each bean defines one or more fields, plus it subclasses HashMap where T is a parameterised type. The generated fields model explicitly-defined schema properties within a JSON schema, and…
Phil Adams
  • 97
  • 9