2,401 questions
0
votes
0
answers
67
views
How to get JsonSerializer.Deserialize<> to not leave objects as JsonElement? [duplicate]
When I run System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>> all values are converted to JsonElement, instead of the actual value. I expect numbers to be converted to ...
1
vote
1
answer
196
views
Can System.Text.Json tolerate an unrecognized type discriminator during deserialization?
I would like to be tolerant if the JSON payload contains a type my app doesn't know about. Ideally I would like to get information about the errors along with the deserialized object, but at a minimum ...
9
votes
1
answer
4k
views
Spring Boot 4 Jackson Deserialization behaves differently - Cannot map null into type int (set FAIL_ON_NULL_FOR_PRIMITIVES to false to allow)
I have a Spring Boot 4 project with the below controller and DTO:
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org....
2
votes
1
answer
154
views
Newtonsoft for ISerializable classes with a reference loop - use GetObjectData for serialization and ordinary constructor for deserialization
I have a couple of ISerializable classes (simplified):
internal interface IBase : ISerializable
{
int Number { get; }
}
internal interface ITable : IBase
{
ISection Section { get; }
}
[...
3
votes
1
answer
179
views
Deserialization via Newtonsoft for classes with a reference loop, private constructors and private/internal properties setters
I have a couple of classes (simplified):
internal interface ITable
{
int Number { get; }
ISection Section { get; }
}
internal class Table : ITable
{
public int Number { get; private init; ...
0
votes
1
answer
150
views
Deserializing array of objects to concrete .NET types using Newtonsoft
I have a couple of classes (simplified):
internal class OrderItem
{
public string Name { get; set; }
public Order Order { get; set; }
}
internal class Order
{
public IReadOnlyList<...
2
votes
0
answers
91
views
How can I accept a number with a leading 0 in .NET Core?
I'm responsible for maintaining a public ASP.NET Core 8 Web API. One endpoint accepts POST data like this:
{
"xid": 12345,
"message": "Hello, world!"
}
On the ....
0
votes
0
answers
81
views
OpenAPI Generator: Conflicting Kotlin property names with case-sensitive JSON properties
I'm using OpenAPI Generator to generate Kotlin DTOs from an OpenAPI specification. I have a schema where I need to handle two JSON properties that differ only in case: inventoryCharacteristics (...
0
votes
1
answer
121
views
ASP.NET Core model binding ignore extra JSON content
ASP.NET Core Web API endpoint accepts malformed JSON with multiple objects, but only processes the first object, instead of rejecting the request.
The API endpoint I'm working on should accept only a ...
0
votes
2
answers
78
views
How does a custom JsonSerializer concat multiple fields into a single string, using each field's own serializer during the concatenation in Jackson?
I am learning to use Jackson's custom serialization and deserialization capabilities to handle the DatePair class. I hope to concatenate the fields of DatePair into a single string.
Here is a MCVE ...
0
votes
2
answers
173
views
Case insensitive JSON parameter names in FunctionsApplicationBuilder
I have scaffolded an Azure Functions application using .NET 9. The Program.cs file looks like this:
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Builder;
using ...
1
vote
1
answer
188
views
Jackson inheritence deserialize causing infinite loop
I'm trying to deserialize JSON data into Animal.class and Dog.class which extends Animal.class using custom deserializer. The JSON data below is a simplified one and the real JSON data cannot be ...
0
votes
0
answers
65
views
Jackson MismatchedInputException when deserializing JSON into DTO with UUID attribute in Spring Boot Kafka Consumer
I send a JSON message like this to Kafka:
`{
"userId": "aa4db80b-a047-4539-8393-f8cd0e9c10e7",
"username": "user18",
"email": "user18@gmail....
1
vote
1
answer
136
views
How is it possible to use kotlinx.serialization in a Kotlin Script?
I would like to write some easy code like:
@Serializable
data class Mydata(val value: String)
val data : Mydata = Json.decodeFromString(rawJson)
But how can this be made possible inside a stand-...
0
votes
1
answer
77
views
How to make Deserialization work with a private field?
I'm wanting to only expose a list as ReadOnly but it's, but while trying to accomodate that for Deserialization, it's not currently working.
Firstly, to confirm Serialization:
{
"StartTime"...
0
votes
1
answer
526
views
"invalid type: map, expected a sequence" when deserialize a JSON structure with serde_json
I can't catch the error cause.
I have used the same procedure with other similar commands using the following tool:
transform JSON to RUST
Another post takes the problem, but a don't understand the ...
0
votes
1
answer
94
views
Spring data elastic search custom conversions doesn't work
Custom @ReadingConverter isn't being triggered but when I was initially implementing this code it worked normally.
Configuration class:
@Configuration
public class ElasticsearchConfig {
@Bean
...
1
vote
1
answer
424
views
DataMember Name attribute ignored when deserializing a JSON object
I have an issue deserializing a JSON object into my class.
I have a class DocumentListByPolicy that is used as a List<> in another class. For the document list, this is my code:
namespace ...
-1
votes
1
answer
172
views
How to Deserialize JSON into C# objects correctly?
I have a function that calls API requests, and I want to have each request return its own data type according to its purpose.
For that, I created a class called ApiResponse. Here is its code:
...
0
votes
1
answer
286
views
System.Text.Json deserialize class that implements IReadOnlyCollection
I have a class that implements IReadOnlyCollection<T> and I cannot deserialize json string produced during the serialization:
public class MyItems : IReadOnlyCollection<int>
{
private ...
0
votes
1
answer
291
views
Json Deserialization from reader (Utf8JsonReader)
I'm calling JsonSerializer.Deserialize(ref reader, options), but for some reason it isn't working.
public class WeatherForecastJsonConverter : JsonConverter<WeatherForecast>
{
public ...
0
votes
1
answer
137
views
Service Bus SendMessageAsync failing when ApplicationProperties is set with values from a Json Deserialized Dictionary<string,object>
I have a scenario I need to set ApplicationProperties to a Azure Service Bus message. I have dictionary of key, value type <string,object>. I also use System.Text.Json for deserializing the ...
0
votes
2
answers
93
views
Deserialize json object as a string [closed]
I have a class A that has a field string data.
I perform a server request that gets me a json text that I convert to A:
var a = JsonConvert.DeserializeObject<A>(jsonResponse);
The problem is ...
3
votes
1
answer
121
views
Loading a file from disk and use that as value during json deserialization
So to be clear I am going to present a working solution to that problem using Newtonsoft.Json 13.0.3. Said solution does not look very good and I am looking for a better one.
Some context, this is ...
0
votes
1
answer
61
views
JSON::SerializableError when deserializing PascalCased properties using JSON::Serializable in a Crystal app
I’m developing a Crystal application and consuming an API that inconsistently uses PascalCase for some of its endpoint properties, rather than camelCase. Unfortunately, this causes issues with JSON::...
0
votes
1
answer
119
views
JsonConverter does not work when data is received from Form
I have added a custom json converter to trim all strings coming to the web api during de-serialization, like this
options.JsonSerializerOptions.Converters.Add(new TrimStringJsonConverter());
And this ...
-1
votes
1
answer
56
views
Issues accessing API data as string array
I am creating an API to receive data from a webhook and process it. I've set up a class to contain the POST data and can access all but one of the fields - the groups, which is set up as a string ...
0
votes
1
answer
59
views
Json deserialization does not set certain object property
I have this class definition:
public class TrabajadorViewModel
{
public int ID { get; set; }
[Display(Name = "Habilitado")]
public bool Habilitado { get; set; }
[Display(...
-1
votes
1
answer
328
views
JSON parse error: Cannot construct instance: no int/Int-argument constructor/factory method to deserialize from Number value
I am trying to insert user record using mysql database
Customer.java
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType....
1
vote
2
answers
88
views
Deserialize json field that may be either array or map
I'm getting json data from server API to Android app (Kotlin Serialization + Retrofit)
I need to parse a Json with field errors. The issue is the structure of this field.
If there are no errors I get ...
1
vote
0
answers
88
views
ASP.NET Core: Is there a way to throw multiple errors in a custom JsonConverter? Or access the ModelState?
I have problem inside a custom JsonConverter that I am potentially catching multiple errors (through attempting to deserialize the JSON, and if it fails, remove the offending propertry and try again) ...
0
votes
1
answer
54
views
Cannot apply indexing with [] to an expression of type object
I'm working on API on the .NET Windows form. I copied the code from the website provided and I found an error
say:
Cannot apply indexing with [] to an expression of type 'object'
How to fix this?
...
1
vote
0
answers
35
views
Spring, deserialization and kotlin nullable types
Let's imagine I have the following classes:
data class MyClass1(
val someField1: String,
val myClass2: MyClass2?,
)
data class MyClass2(
val someField2: String,
val someField3: String?,
)
...
0
votes
0
answers
38
views
How do I deserialise a class property of type Object in VB Net with System.Json
In VB .Net, I use System.Json to (de)serialise a class called Model. This class has a list of changes, where a change has three properties: PropertyName, OrignalValue and NewValue.
The PropertyName ...
-2
votes
1
answer
169
views
C# JSON: I want to deserialize an empty string to a custom type. But it seems to be always defaulting to null. Is there a way to achieve this
I want JsonConvert.DeserializeObject<CustomType>("") to be deserialized to new CustomType()
but this is always deserialized to null.
this is using Newtonsoft json, have tried using a ...
1
vote
0
answers
196
views
do not serialize empty collections (and handle accordingly in deserialization)
I have a bunch of POCOs that can be (de-)serialized from/to json. A lot of content is collections. I want the serialized JSON to only contain a specific property if its collection is not empty (...
-2
votes
2
answers
129
views
Deserialization error on the 3rd library class instance in the class (using Lombok annotations) [duplicate]
I want to use a 3rd party (external) class instance in a class but I am getting this error on deserialization:
Cannot construct instance of org.springframework.data.geo.Point (no Creators, like ...
2
votes
1
answer
360
views
What is the proper way to customize deserialization process for JsonNullable of particular type
I want to customize JsonNullable<Boolean> deserialization process. So I've found the class JsonNullableDeserializer :
I've implemented my own deserializer:
public class ...
0
votes
1
answer
481
views
Why is using JsonSerializer.DeserializeAsyncEnumerable to deserialize a 1GB file resulting in 2GB+ memory allocation?
I need to deserialize a 1GB json file one element at a time in a streaming fashion and after doing some reading found JsonSerializer.DeserializeAsyncEnumerable to enable this while also keeping the ...
1
vote
1
answer
87
views
Configure Jackson Deserialzer using static method for types with a given super class
Currently I am getting an exception when deserializing a codestable typed class.
Imagine the following scenario:
public abstract class AbstractCodestableEntry implements java.io.Serializable {
...
1
vote
1
answer
213
views
Newtonsoft - Deserialize JSON ignore underline without JsonProperty
I have a JSON like this:
{
"part_1": "",
"part_2": "",
"part_3": "",
"part_4": "",
"part_5"...
0
votes
1
answer
79
views
De-serialize JSON string into .NET object
I have a JSON string something like below:
[
{
"movie title": "The Matrix",
"release date": "1999-03-31",
"movie rating": 8.7,
"...
0
votes
0
answers
491
views
How to serialize and deserialize nested java objects when sending object to Kafka topics and receiving at consumer end using only Jackson
I am new to custom serialization/deserialization and also using it in Kafka is even more new for me. I am trying to explain what I am doing and also what I want to achieve. Please comment if you need ...
0
votes
1
answer
122
views
How do I deserialize additional properties present in a type for which a converter already exists?
I am attempting to deserialize a geojson FeatureCollection. The API I am querying returns this feature collection with additional properties on the type. The properties are used for cursor-based ...
0
votes
1
answer
166
views
Using upickle read in Scala 3 macro
Try to write a generic macro for deserialising case classes using uPickle read in Scala 3:
inline def parseJson[T:Type](x: Expr[String])(using Quotes): Either[String, Expr[T]] = '{
try
Right(...
17
votes
4
answers
3k
views
Unable to get route object from currentBackStackEntry in Compose Navigation outside NavHost composable block using toRoute extension
I am working on a project that utilizes Jetpack Compose Navigation with Type-Safe Navigation. Within my application, I have an composable function responsible for hosting the navigation graph. Here's ...
1
vote
0
answers
48
views
"Option type"-esque deserialization of API response in .NET Core [duplicate]
I'm using .NET's native JSON utilities (System.Text) to perform automatic Serialization/Deserialization of data going to and from an API. The API responses are structured like the following:
{
&...
2
votes
1
answer
2k
views
How can I use Jackson's @JsonAnySetter with a record class?
I'm trying to use Jackson's feature to deserialize unknown fields into a map, using @JsonAnySetter. This works fine for a Java class with the field annotated with @JsonAnySetter, but does not work ...
0
votes
1
answer
135
views
C# - Deserialize DateTime & DateTimeOffset values to UTC and Local Time as required
I'm currently working on a full stack application that has never had to be conscious of time zone, but looks like it will soon need to be a bit more versatile in terms of being aware of local time ...
1
vote
1
answer
921
views
Using kotlin kotlinx serialization with generics
Hi everyone I have the following code that I use to serialize into json strings to store in shared preferences
interface Serializer {
public fun <T> serialize(data: T, type: Class<T>): ...