Questions tagged [json-serialization]
302 questions
3
votes
2 answers
How to serialize private fields in json-serializable?
Minimal reproducible code:
@JsonSerializable()
class A {
final int _x;
A(int x) : _x = x;
factory A.fromJson(Map json) => _$AFromJson(json);
}
Note:
I don't want to make my private field _x public or define a public x…

iDecode
- 22,623
- 19
- 99
- 186
3
votes
1 answer
json_serializable enhanced enums not working. This requires the 'enhanced-enums' language feature to be enabled
I'm using the latest version of all these packages.
dependencies
json_annotation: ^4.5.0
dev_dependencies:
json_serializable: ^6.2.0
build_runner: ^2.1.10
I also found that json_serializable: 6.1.5 added support for enhanced enums. But when…

iDecode
- 22,623
- 19
- 99
- 186
3
votes
1 answer
Is there anyway to check the class type of an object BEFORE deserializing in C#?
So for instance I have several types of cars that are being serialized to a .car file (this is a school project). I have three different types, ford, lexus, and dodge. I can save them fine. But with the current architecture of my program, when I…

Connor
- 113
- 8
3
votes
3 answers
Problem serializing a list of objects in flutter and saving it using shared preferences
I have been trying to save a list of type Contact (which is a class from contacts_service) package by serializing it using toJosn and fromJson and then saving it as String in Shared Preferences
to & fromJosn :
Contact.fromJson(Map…

Anan Saadi
- 328
- 4
- 21
3
votes
1 answer
Set Default value for missing Complex properties with JSON.net (JsonConvert.SerializeObject or JsonConvert.DeSerializeObject)
I have a requirement where I need to set default value to the below complex property Instances using JsonProperty and DefaultValue.
I know we can achieve this for primitive properties as mentioned in the below link, but need to know how we can do it…

Vinay Gangaraj
- 111
- 1
- 8
3
votes
2 answers
ASP.NET Core not binding arguments from body after upgrade to 3.1
I just upgraded an ASP.NET Core project from 2.2 to 3.1 and now my model binding doesn't work for POST requets. I read that the default JSON serializer changed from Newtonsoft.JSON to System.Text.Json in .NET Core 3. Could this be the reason?
My…

Thorkil Værge
- 2,727
- 5
- 32
- 48
3
votes
3 answers
Flutter: complex json serialization. Parsing json string to provide into UI
Here is the json string that I get by http request.
The aim is to display subjects according to the current weekday.
{
"first_name": "First Name",
"batch_name": "Batch 1",
"enrolled_subjects": [
"Subject 4",
"Subject 5"
…

JC18
- 65
- 5
3
votes
2 answers
Gson: StackOverflowError during serialization
I wrote this class and i need to serialize the field gameTimer, whose type is the interface TimerP.
public class PlayerImpl implements Player {
@Expose
private final String nickname;
@Expose
private final TimerP gameTimer;
@Expose
private final int…

coolitos
- 39
- 2
3
votes
0 answers
iOS 12 equivalent of JSONSerialization.WritingOptions.withoutEscapingSlashes (Swift)?
My code:
let json: [String: Any] = ...
request.httpBody = try JSONSerialization.data(withJSONObject: json, options: .withoutEscapingSlashes)
The problem is it works in iOS 13 only but I need to support iOS 12 too.
How to fix it correctly? Should I…

Vyachaslav Gerchicov
- 2,317
- 3
- 23
- 49
3
votes
4 answers
.Net Core 3.0.100-preview6 - API Json responses are always camelcase, but my classes are not
I have a .net core 3.0 preview 6 MVC application and API.
In the API, I am using a third party class library (that I can't change) which defines the class properties as Pascal cased with the JsonProperty, PropertyName snaked cased eg...
public class…

Gary Thornton
- 53
- 7
3
votes
1 answer
How does receiving application knows which serialization mechanism has been used?
I am receiving bytes of data onto a kafka topic and those bytes can be sent (by an application) by using plain Java Serialization or JSON serialization or protocol buffer.
So, now when my application reads those bytes from kafka topic, how does it…

CuriousMind
- 8,301
- 22
- 65
- 134
3
votes
1 answer
Custom json serialization java primitives from kotlin by Jackson
In my project there are java and kotlin modules. In some kotlin module I need a custom serialization. All long values should be serialized as string. I use Jackson.
Example:
kotlin
data class KotlinRecord(val id: Long)
java
public class…

V. Kuznetsov
- 609
- 1
- 7
- 18
3
votes
5 answers
Generate a Json Serializable Generator using Build Runner in Flutter: Response is Succeeded, but no output is being generated
I have an issue when trying to generate a Json Serializable Generator using Build Runner in Dart. First, I tried to do run flutter packages pub run build_runner build to generate Json Serializable but it showed that it has a conflicting issue. So I…

flutteria
- 151
- 2
- 8
3
votes
1 answer
iOS - JSONSerialization VS JSONDecoder and usage
So i am getting the follow json :
{
"output": [
"{\"cameraIsOnboarded\" : true}"
],
"exit_code": 0
}
i tried to decode it with the model below:
struct CameraOnboard: Codable {
var output: [Output]
//var exit_code: Int?
}
struct Output:…

ironRoei
- 2,049
- 24
- 45
3
votes
2 answers
'_InternalLinkedHashMap' is not a subtype of type 'Iterable' in type cast
I am trying to use built_value and json_serializable together for parsing json response coming from server to model classes.
Following are the dependencies:
built_collection: ^4.0.0
built_value: ^6.1.4
dev_dependencies:
build_runner: ^1.0.0
…

vipin agrahari
- 2,691
- 3
- 21
- 31