Questions tagged [json-deserialization]

JSON deserialization is the process of converting a JSON string into an instance of an object, often a class.

JSON (Object Notation) is an efficient data encoding format that enables fast exchanges of small amounts of data between client browsers and -enabled Web services.

JSON deserialization is the process of converting a JSON string into an instance of an object, often a class. JSON encoded strings carry both structural and data information, so the instance of the object resulting from deserialization is a well-defined, data-filled object.

For example the following string:

string json_encoded_string = @"{""name"" : ""John"", ""surname"" : ""Doe"", ""age"" : 38}";

can be deserialized into an instance of the following class:

class Person
{
    public string name { get; set; }
    public string surname { get; set; }
    public int age { get; set; }
}
2322 questions
0
votes
0 answers

How do I do something with the JSON data before mapping it to a Java object with Jackson?

I want to be able to do something with the totalNumber in the JSON before assigning it to the TotalNumber object. Is there a way to do that with Jackson? public class Numbers { private TotalNumber totalNumber; } [{ "totalNumber": [1,2,3,4] }]
Jon
  • 453
  • 5
  • 18
0
votes
1 answer

Newtonsoft Json Deserialization 1 json property to decimal or int c# properties

How to achieve below deserialization. value in JSON sometime int and sometime it's decimal. I am working under multiple restrictions so - can't change value as int property. It may break existing contract and this is use all around system. have to…
PKV
  • 773
  • 1
  • 7
  • 17
0
votes
2 answers

I have json in below format, how can i Deserialize it in C#

{ "status": "success", "data": { "custid1": 723, "custid2": 670, "custid3": 430 } } It doesn't have key-value pair it just contains the value of two columns. I have tried it by converting it into a data table but…
0
votes
2 answers

How to display only specific field from nested JSON

I have a nested JSON that I am reading data from. I would like to take only one specific field and display it in the console. To map my JSON in object model I created 3 classes CarResponse, Car and CarValue. CarResponse.java public class CarResponse…
user9347049
  • 1,927
  • 3
  • 27
  • 66
0
votes
1 answer

Spring Kafka listener to consume JSON and infer the domain object

I have a topic that will be published with multiple types of JSON messages. I don't have control over the publisher code to add any headers etc. But, I want to leverage @KafkaHandler to handle the different JSON messages inferred to the domain…
0
votes
3 answers

How to serialize a Date as LocalDate in Jackson?

I have a class with a field of type LocalDate: public class MyClass { private LocalDate myDate; } I have to store the value as yyyy-MM-dd instead of as [yyyy, M, d] Which can be done creating a LocalDateSerializer as indicated in…
j.xavier.atero
  • 506
  • 2
  • 10
  • 25
0
votes
0 answers

cant consume json data from kafka topic in scala

I need to read json data from kafka topic. I am not able to consume json data from kafka topic.It will in infinite loop. So far I suppose I need to: Implement a custom serializer to convert JSON into byte array implement a custom deserializer to…
0
votes
1 answer

Serialization Exception in Spring-kafka Consumer Exception

When sending any message to my SpringBoot Kafka application, I am facing the Serialization Exception, here is the log. 2021-02-24 01:28:21.280 INFO 19249 --- [nio-8080-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka version:…
0
votes
1 answer

ServiceStack JsConfig.Init DateHandler to Local Time

I'm using JsConfig.Init(new Config {DateHandler = DateHandler.UnixTimeMs}); as was previously suggested and it's deserializing now but the times are all wrong due to it assuming UTC rather than local time. How do I tell the deserializer to assume…
LorneCash
  • 1,446
  • 2
  • 16
  • 30
0
votes
1 answer

Same type serialization based on field name in GSON without annotations

Given a class that I cannot modifiy class ThirdPartyDTO { Instant foo; Instant bar; // many more fields. } I have a JSON representation of the class that uses two diferent patterns to represent foo and bar. If the field name is foo, use this…
Jorge Lavín
  • 937
  • 8
  • 22
0
votes
0 answers

How to prioritize Newtonsoft's object reference resolution before type inheritance when deserializing in C#?

I need object inheritance (using [JsonConverter(typeof(JsonInheritanceConverter), "_type")]) and object reference (using JsonSerializerSetting.TypeNameHandling = Auto) at the same time. Serialization works fine, but deserialization ends with…
0
votes
3 answers

How to deserialize multiple json fields into one custom object

I'm trying to deserialize a json like this: { //other fields "name": "John", "surname": "Doe" } into an object like this: public class SomeClass { //other fields private User user; public class User { private String name; …
Daesos
  • 99
  • 10
0
votes
1 answer

Using @JsonCreator to create two instances of same class in one JSON DTO

I would like to deserialize JSON of this structure: { "employee_pricing_type":"COMPUTE_BY_OWN_RATE", "employee_rate":10, "customer_pricing_type":"COMPUTE_BY_OWN_RATE", "customer_rate":200 } I have such POJO to create price setting from a…
jnemecz
  • 3,171
  • 8
  • 41
  • 77
0
votes
1 answer

Unable to deserialize JSON response

Hi I am Getting an XML response from the API and I am converting that XML response to JSON and then ingesting data in database using C# objects. After converting that XML into JSON and deserializing that JSON is throwing me the error as…
Abdul
  • 176
  • 3
  • 19
0
votes
1 answer

json parsing to pojo for a variable which is an Object or two Object using jackson

How to parse json to pojo for a dynamic property variable in java. Rest api returns data : "db": { "queryA": { "name": "A", "age": "12", "startDT": "202102030800" } } OR sometimes …
CodeGeek
  • 31
  • 1
  • 7