Encountered an issue while trying to read the JSON document: Unable to convert the START_OBJECT token into an instance of java.lang.String

I encountered an issue while attempting to send a value to my controller.

Failed to read HTTP message: 
org.springframework.http.converter.HttpMessageNotReadableException: Could 
not parse JSON document: Unable to deserialize java.lang.String from START_OBJECT token
at [Source: java.io.PushbackInputStream@355134ca; line: 1, column: 655] 
(through reference chain: com.csps.gabriel.entities.Policy["goodsList"]-
>java.util.ArrayList[0]->com.csps.gabriel.dtos.GoodsDto["type"]); nested 
exception is com.fasterxml.jackson.databind.JsonMappingException: Unable 
to deserialize java.lang.String from START_OBJECT token
at [Source: java.io.PushbackInputStream@355134ca; line: 1, column: 655] 
(through reference chain: com.csps.gabriel.entities.Policy["goodsList"]-
>java.util.ArrayList[0]->com.csps.gabriel.dtos.GoodsDto["type"])

This is the JSON I posted:

{
"client": {
    "clientId": 1000002,
    "firstName": "Jose Anibal",
    "lastName": "Rodriguez Lopez",
    "idCard": "07200140809",
    ...
}]

}

This piece of code represents the entity that maps the request body:

@Entity
@Table(name = "policy")
public class Policy {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "policy_id")
...
}

}

This is the defined controller:

@RestController
public class PolicyController {

@Autowired
PolicyRepository policyRepository;

@RequestMapping(value = "/save-policy", method = RequestMethod.POST, 
consumes = MediaType.APPLICATION_JSON_VALUE)
...
}
}

This snippet presents the GoodsList class:

package com.csps.gabriel.dtos;

import java.io.Serializable;

/**
Created by Jose A Rodriguez on 5/20/2017.
*/
public class GoodsDto implements Serializable{

private static final long serialVersionUID = 1L;
...
}
}

If anyone has any insights on why this error is occurring, please share. Thank you in advance!

Answer №1

The issue lies with the member GoodsDto.type. It is defined as a String in your GoodsDto class, but you are attempting to provide it a 2-field structure in your JSON:

"goodsList": [{
    "type": {
        "name": "Jeep",
        "index": "1"
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Label it as submit ID rather than value or label

Check out this awesome plugin called https://github.com/aehlke/tag-it. It's really cool! Here is the issue I'm facing: <input type="hidden" name="tags" id="mySingleField" value="Apple, Orange" disabled="true"> Tags:<br ...

obtain the computed style using selenium

I'm trying to retrieve a computed style attribute (pointer-events) that I can view in the Browser dev-tools, as shown in the screenshot. Methods like element.getAttribute("style") are not providing me with the computed styles. How can I use ...

Obtaining access to JavaScript data from a child element is crucial

A client has implemented a feature on their webpage that detects changes made in a grid of data and prompts the user to save before leaving. If users feel confused or encounter multiple errors, they can simply cancel their changes and start over. They hav ...

The script remains static and does not alter the "href" or "div" content based on the current URL

I am having an issue with my NavMenu on my website. It is a table with images that link to product pages, and I want to change the links and names based on the language of the site. However, the script I wrote for this is not working properly. I have tried ...

The intricacies of a many-to-many relationship and how to populate associated data within a query when using Keystone

I'm currently working on a KeystoneJS project and encountering an issue with the relationships between two models. Here are the details of the two models: User model: User.add({ name: { type: Types.Name, required: true, index: true }, email ...

Step-by-step guide to initializing a project using React with Typescript and a functional server-side script

I am working on a project that involves a React Typescript app (created using Create React App). In this project, I need to have an executable script that can run alongside the React app. Both the app and the script are intended to only run on local machin ...

How can I ensure that VueJS only starts loading data after the initial API call has been completed?

After retrieving data from an API, I populate a form in my component. The challenge I am facing is that the watchers are triggered immediately after populating the initial data. I want them to be triggered asynchronously. Additionally, I need to prevent th ...

The behavior of JavaScript execution when typing in a text field does not align with the expected sendKeys method

Whenever I run my tests on a Linux machine, I encounter an issue with the way text is typed using the following code snippet: visibleElement.clear(); visibleElement.sendKeys("I am running on linux machine"); Instead of typing the text correctly as expect ...

Ensure that the React Router DOM only loads a component when necessary

I am facing an issue with my code which is fully functional and very basic: import React from "react"; import ReactDOM from "react-dom"; import {BrowserRouter, Route, Switch} from "react-router-dom"; import Home from "./A ...

Unusual Actions of the JSCH Library

I am having an issue while attempting to run multiple commands via SSH using the JSCH library. It seems that when I execute the code in Eclipse, the program finishes running but the command "mkdir test" does not get executed on the server. However, when ...

The jQuery inArray function fails to detect a match when the first element is the one being compared

I want to create an array and check if a specific value is present anywhere in the array. Depending on the presence of the value, I need the code to execute different actions. var Arr = [false, false, false, false, false]; // Works with this array: // Arr ...

Discovering the method to display the non-selected option from the dropdown list in another dropdown list within the same row of a table using jQuery

I've got an HTML table with input text fields and dropdown lists as columns. Two of the dropdown list columns display the same list of options. I'm attempting to remove the selected option in one dropdown from appearing in the other dropdown in ...

Combining similar property objects within a group

I am facing a similar object structure with the goal of summing up the same property grouped by year (e.g., 2016 --> importo1: 7500, importo2: 0, importo3: 0, importo4: 3000) { index: 0, annoDelibera: 2020, importo1: 2500, importo2: 3000, imp ...

Minimizing the size of a production application's bundle

In a production application I am working on, the bundle size is currently 8.06MB. # Output from npm build File sizes after gzip: 1.67 MB build/static/js/3.73cf59a2.chunk.js 794.29 KB build/typescript.worker.js 131.13 KB build/css.worker.js 1 ...

Creating a semi-circle donut chart with Highcharts using the Highcharts-ng library

I have been working on integrating a Highcharts Semi-circle donut chart into my angular application using the Highcharts-ng directive. However, I seem to be facing an issue where the plotOptions section is being skipped entirely, leading to a full circle p ...

Tips on generating a sample Mongoose Model with all null values

Imagine you are working with the following schema: var userSchema = new Schema({ name: String, schools: [{ level: String, name: String, timeInterval: { start: {type:Date,default:Date.now}, ...

Automating the creation of box UVW maps through programming

I'm looking for a way to automatically create box UVW maps in 3D models, similar to the functionality of UVW Map -> Box in programs like 3ds Max. Here's an example with the default UV mapping And here is an example with the desired box UV ma ...

Generating XSD from XML elements: A step-by-step guide

Currently, I have an XML input that looks like this: <field> <name>id</name> <dataType>string</dataType> <maxlength>42</maxlength> <required>false</required> </field> Is there a library ...

Can you explain to me the concept of "face indices" in Three.js and how it functions?

I am attempting to use Three.js to build a unique irregular polyhedron. In order to achieve this, I have decided to utilize the PolyhedronGeometry feature (refer to the documentation). However, I am encountering difficulty in understanding the concept of ...

"I am sending a JSON object to a PHP script and extracting the

I have created a form with PHP like this: <?php include '../db/baza.php'; ?> <?php include 'vrh.php' ?> <div id="page"> <div id="pageFrame"> <form action="up ...