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
3 answers

python: json print root object names

I have a JSON String like this: { "Sommersprossen": { "count": 5, "lastSeenTime": 1586959168567 }, "inkognito": { "count": 7, "lastSeenTime": 1586901586361 }, "Marienkäfer": { "count": 7, "lastSeenTime":…
0
votes
1 answer

Jackson serializer for ValueObject hierarchy - polymorphic

As a continuation of jackson-serialize-simple-one-attribute-valueobject-like-enum-without-nesting I would like to be able to create Wrapping one attribute ValueObjects in a very simple manner, just by inheriting from base ValueObject…
bastiat
  • 1,799
  • 2
  • 19
  • 38
0
votes
0 answers

Using JsonConverter on a property that is sometimes missing, as well as checking for single item or array

In the Json deserialization model, I have a class member that can be a single item or an array, thus I use a JsonConverter to deal with it. However, sometimes the entire property is missing in the response as well. The model has a property that the…
ProgrammerBret
  • 137
  • 2
  • 12
0
votes
1 answer

Apache Camel when deserializing an object, it throws an exception: com.fasterxml.jackson.core.JsonParseException: Unrecognized token

I have a rest api that returns a String: @GetMapping("/api/users") public String getUsers(){ return "DENIS"; } I'm calling this api from apache camel: from("direct:start") .setHeader(Exchange.HTTP_METHOD).constant(HttpMethod.GET) …
Denis Denis
  • 77
  • 1
  • 9
0
votes
3 answers

C# MVC can't Deserialize a tuple

I have a Json model that looks like this private class SearchMetadataJson { public string entertain { get; set; } public string master { get; set; } public string memail { get; set; } public string key { get; set; } …
ChristianOConnor
  • 820
  • 7
  • 29
0
votes
0 answers

TypeNameHandling.All vulnerability scenario

I'm trying out Azure Durable Functions and I need to pass an external class as input/output between the Activity Functions. This class comes from an external SDK and it contains abstract classes & interfaces. Because of this, the function throws an…
adelb
  • 791
  • 7
  • 26
0
votes
1 answer

How to make fields in type class mandatory based on the parent class during deserialization

I am trying to deserialize my JSON and everything is working fine but I would like to add few conditions to make it better. Following is my Parent class based on which deserialize happen: public class ParentJSON{ @NotNull private String…
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
0
votes
0 answers

Parsing Unescaped Json With Spring Boot

I'm trying to parse a json response from a 3rd party API, but some of the values are unescaped. Here's an example (taken from https://ratings.food.gov.uk/OpenDataFiles/FHRS760en-GB.json (line 35549)): { "FHRSEstablishment": { "Header":…
Adam
  • 610
  • 1
  • 7
  • 21
0
votes
0 answers

DateTime Deserializing with TypeNameHandeling fails - date is initialized to the default dateTime value - C#

I have the following classes: public class ScheduledTask { public Frequency Frequency { get; set; } public DateTime LastRun { get; set; } public string Status { get; set; } } Frequency class: [BsonDiscriminator(RootClass =…
0
votes
1 answer

Deserialize json using Java Jackson and based on the root element call different classes that match the Json Object within that root element

I am new to deserialization and I am trying to deserialize the complex JSON for my class. I am using Jackson 2.12.1. I wanted to know how to map the following JSON structure to my class when there are multiple cases that map to the different root…
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
0
votes
1 answer

How to create multiple PropertyNames for one instance of class NewtonSoft

So, I try to deserialize JSON file that has a format "farmableitem": [ { "@uniquename": "T1_FARM_CARROT_SEED", "@tier": "1", "@kind": "plant", "@weight": "0.1", "harvest": { "@growtime":…
0
votes
2 answers

Unable to cast object of type 'System.Collections.Generic.List`1[MW01.Web.Model.Countries]' to type 'MW01.Web.Model.Country'.'

I am trying to deserialize an object from API but I keep getting either cast error. Here is my Country class: public class Country { public List country { get; set; } } public class Countries { …
fourseven
  • 3
  • 1
  • 4
0
votes
1 answer

I cannot output the value of the foreign key via jsonresponse serealize

I want to get json serialized the name of the products insted of the id ones. I tried to add natural_keys method on the parent model with no luck. I can receive the json data good but in this way: [{"model": "ocompra.compradetail", "pk": 1,…
0
votes
1 answer

AttributeError: 'list' object has no attribute 'tolist'

It's a two part question, import face_recognition import os import json loadarr=[] encodearr=[] for i in range(0, 4): loadarr.append(face_recognition.load_image_file( "brad"+str(i+1)+".jpg")) …
0
votes
1 answer

Failed to denormalize attribute "date" value for class

I am trying to save by API an object given by the Front in React JS So I have this object testing in Insomnia: { "rate": 1.59, "correction":"2 ui nOVORAPID", "date": "2020-11-26", "time": "7:30"} I don't understand why i have the error Failed to…