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
4
votes
2 answers

JsonSerializerSettings to change case of property name but not name of property's property

I am using below settings for camel casing of my class property. JsonSerializerSettings settings = new JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() …
Microsoft Developer
  • 5,229
  • 22
  • 93
  • 142
4
votes
3 answers

JSON Serialization of a Django inherited model

I have the following Django models class ConfigurationItem(models.Model): path = models.CharField('Path', max_length=1024) name = models.CharField('Name', max_length=1024, blank=True) description = models.CharField('Description',…
4
votes
1 answer

Play/Scala how to prevent Json serialization of empty arrays?

I want to recursively write a class to Json, so I'm using the following implicit writes: implicit val writesObject : Writes[Object] = ( (__ \ "id").writeNullable[String] ~ (__ \…
jmend
  • 1,210
  • 4
  • 16
  • 30
4
votes
1 answer

How to map JSON response to custom class object

I am calling an API in C# using unirest.io. I get following JSON response (as response.Body). { "persons": [{ "id": "a010", "name": "Joe", "subjects": [ "Math", "English" ] }, { …
theGeekster
  • 6,081
  • 12
  • 35
  • 47
4
votes
1 answer

Jackson EnumMap key serialization

Does Jackson allow you to customize how it serializes EnumMap keys? For example, if I have public enum MyKey { ABC, DEF, XYZ; public String getKey() { return "my-key-" + ordinal(); } } and some public class MyObject { …
ManRow
  • 1,563
  • 4
  • 21
  • 40
4
votes
3 answers

Rename field in JsonSerializer

I have a class library that I need to output via a JsonResult in the ASP.NET MVC framework. (JsonResult uses the JsonSerializer to produce its output.) I discovered through reading the documentation that if you put [ScriptIgnore] on a public…
David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
4
votes
2 answers

ASP.Net Web API. JSON and XML responses in one project

I have an ASP.Net Web API project which already contains controllers to return result in JSON format. Now I have to add new controllers which should receive and return only XML. I know that I can use the following option to push controllers to…
Antipod
  • 1,593
  • 3
  • 23
  • 43
3
votes
1 answer

sequential calls of methods asynchronously

I have a list of methods I am calling in a method, as follows: this.doOneThing(); someOtherObject.doASecondThing(); this.doSomethingElse(); When this is synchronous, they are executed one after the other, which is required. But now I have…
Loic Duros
  • 5,472
  • 10
  • 43
  • 56
3
votes
2 answers

Serialize a list of Objects of different Classes (implementing a common Interface) rendering only the Interface Properties (as IActionResult)

I wrote a Controller Action that needs to return a Json with a List of Sports. This Json Array only needs to contain the common properties (defined at the Interface level). The Interface definition is: public Interface ISport { string TeamName…
3
votes
1 answer

Could not generate `fromJson` code for `images` because of type `Asset`

I am using freezed with json generator. i am facing this error on generating the code. Could not generate fromJson code for images because of type Asset. The Code Is: abstract class ProductDTO with _$ProductDTO { factory ProductDTO({ …
user16906111
3
votes
1 answer

freezed how to assign my own JsonConverter on top level model?

I have freezed model (simplified): part 'initial_data_model.freezed.dart'; part 'initial_data_model.g.dart'; @freezed class InitialDataModel with _$InitialDataModel { const factory InitialDataModel() = Data; const factory…
Nagual
  • 1,576
  • 10
  • 17
  • 27
3
votes
1 answer

How to parse complex nested JSON in java?

I have a complex nested Json It has a body similar to this: { staus: "Success", id: 1, data: [{'Movie':'kung fu panda','% viewed': 50.5},{'Movie':'kung fu panda 2','% viewed':1.5}], metadata: {'filters':['Movie', 'Percentage Viewed'],…
rrond
  • 33
  • 2
3
votes
1 answer

Is it possible to find unmapped properties in System.Text.Json?

Is it possible to find unmapped properties with the System.Text.Json.JsonSerializer? I'm accessing an API which returns an array of documents. I want to know if there is a way to know if there is an property in the json document which is not mapped…
boop
  • 7,413
  • 13
  • 50
  • 94
3
votes
2 answers

flutter build runner not working - The getter 'uri' was called on null

I was using flutter with build runner perfectly , but today it just getting this null error . Even thought I reverted my code changes but still the same error . the error : >[SEVERE] json_serializable:json_serializable on…
Killua San
  • 194
  • 1
  • 4
  • 12
3
votes
1 answer

Object Serialization to bytes vs Jackson serialization from Object to JSON?

My question may sound very basic one but I am a bit confused on jackson s writeValueAsString(String) is also called as serialization and conversion of java object to byte stream is also called as Serialization. Can anyone help me understand; how…
Jaraws
  • 581
  • 1
  • 7
  • 24