Encountered an issue while attempting to assess Jackson deserialization for this specific

I am currently in the process of establishing a many-to-many relationship between movies and users. However, I encountered an error while attempting to save a movie:

2017-12-01 16:12:43.351 WARN 17328 --- [nio-8090-exec-5] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.movieseat.models.Movie]]: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference': back reference type (java.util.List) not compatible with managed type (com.movieseat.model.security.User)

2017-12-01 16:12:43.354 WARN 17328 --- [nio-8090-exec-5] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.movieseat.models.Movie]]: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference': back reference type (java.util.List) not compatible with managed type (com.movieseat.model.security.User)

2017-12-01 16:12:43.356 WARN 17328 --- [nio-8090-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

An issue arose:

org.hibernate.collection.internal.PersistentBag[0]->com.mo‌​vieseat.model.securi‌​ty.User["authorities‌​"]->org.hibernate.co‌​llection.internal.Pe‌​rsistentBag[0]->com.‌​movieseat.model.secu‌​rity.Authority["user‌​s"]

This was resolved by modifying User.java:

@JsonManagedReference                
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
        name = "USER_AUTHORITY",
        joinColumns = {@JoinColumn(name = "USER_ID", referencedColumnName = "ID")},
        inverseJoinColumns = {@JoinColumn(name = "AUTHORITY_ID", referencedColumnName = "ID")})
private List<Authority> authorities;

And Authority.java:

@JsonBackReference
@ManyToMany(mappedBy = "authorities", fetch = FetchType.LAZY)
private List<User> users;

However, it seems that I also need to add an annotation to my Movie.java model. The error message indicates:

Can not handle managed/back reference 'defaultReference': back reference type (java.util.List)

In an attempt to rectify this, I included a @JsonBackReference to the relation in my Movie.java model:

@JsonBackReference
@ManyToMany(mappedBy = "movies")
private Set<User> users = new HashSet<>(); 

Unfortunately, this did not solve the issue. Is there something else that I may have overlooked?

Answer №1

To resolve this issue, I made the necessary changes in my User.java file by including the following code:

@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class User {

This modification helped address the issue at hand.

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

An error is triggered in the express body-parser when attempting to post a string, resulting

Below is a simplified version of the code I am working with: 'use strict' const express = require('express') const bodyParser = require('body-parser') const app = express() app.use(bodyParser.json()) const storage = {} ap ...

Turning a JSON formatted string into parameters for a function

Looking to convert a string of JavaScript objects into function arguments. The string format is as follows: "{ "item1": "foo 1", "item2": "bar 1" }, { "item1": "foo 1", "item2": "bar 2" }" While I can use JSON.parse to turn it into an array, the challeng ...

A guide on transmitting login details via HtmlUnitDriver and Selenium using Java

I am attempting to automate the process of sending login credentials using HtmlUnitDriver for a website. The website URL is , however, I am encountering a NoSuchElementException. Sample code snippet: package example; import org.openqa.selenium.By; import ...

In WebDriver, the NoSuchElement exception does not occur when a web element is not found on a page

Unexpectedly, the NoSuchElement exception does not occur when a webElement is not found on a page in WebDriver. In situations where the webElement is present on a page, all operations performed on it will function as expected. However, if the webElement i ...

Tips on identifying elements from 2 ArrayLists merged into a single ArrayList and using a ListViewAdapter

Apologies for the complex Title (it's hard to summarize my issue in a few words) Here is my current situation: I am working on an app that collects Stamps. I have a JSON file that contains 2 JSONArrays for "collectedStamp" and "unCollectedStamp". Th ...

Unable to display the response received in jQuery due to a technical issue with the JSON data

Hey there! I'm fairly new to JSON and web development, so please bear with me if I'm not explaining the problem in the most technical terms. I recently encountered an issue where I retrieved a JSON response from a website, but I couldn't di ...

Is there a way to transfer an array of strings and integers from JavaScript to Python 3.8?

I have reviewed similar questions but haven't found a solution that works for me. My inquiry is regarding the following code snippet: function pyInput(){ const buffers = []; proc.stdout.on('data', (chunk) => buffers.push(chunk)) ...

An issue with JsonException when using Selenium Chromeoptions

As someone new to Automation, I am trying to run the code below but encountering a JsonException. Despite reading that desired capabilities are deprecated and trying to use chromeoption.merge(capabilities), I am still facing issues. Can anyone please ass ...

Encountered a SyntaxError on JSON Web Tokens Node JS Server: Unexpected token } found in JSON at position 24

Me, along with others, have encountered this issue: SyntaxError: Unexpected token } in JSON at position 24 at JSON.parse (<anonymous>) while following a tutorial on JSON Web Tokens (TUTORIAL LINK: https://www.youtube.com/watch?v=mbsmsi7l3r4&t=34s ...

Selenium Tutorial: How to Open a Link in the Same Tab

When I click a link using Selenium webdriver, it sometimes opens up in a new window. Is there a way to make the link open in the same window (and tab) instead? This behavior only occurs with a specific link most of the time. Thank you ...

Encountering a 404 Error with jQuery Ajax Call Version 3.5.1

The ajaxCall function is returning a 404 error during the onChange select event. My application uses Spring Boot + BootStrap + Thymleaf + jQuery 3.5.1. The URL parameter corresponds to an internal spring boot @RequesteMapping. ERROR: jquery-3.5.1.min.j ...

An error has been encountered: JSONDecodeError Unable to find expected value at line 1, column 1 (character 0) While trying to address the previous error, a new exception occurred:

import urllib.request import json def printResults(data): theJSON = json.loads(data) if "title" in theJSON["metadata"]: print(theJSON["metadata"]["title"]) count = theJSON["me ...

Customizing the SBJson library to fit the needs of my application

I recently came across the SBJson framework on GitHub (truly brilliant) https://github.com/stig/json-framework/ For example, you can visit: The Twitter example I tried worked perfectly. Then, I decided to update my URL and for (NSDictionary *status in ...

Exploring the depths of JavaScript JSON elements

After processing my PHP code, it generates a JSON output that contains multiple entries in the same structure. Here is an example with two entries: { "0": { "campaign_id": "31", "title": "new title", "description": "new descrip ...

The interface is unable to populate the Array of Elements

When using Angular, I send a request and save the response in a variable: conversations: Conversation[]; // ChatService getConversations() { return this.http.get<Conversation[]>('/chat/conversations'); } this.chatService.getConversat ...

A better method for extracting the Kubernetes pod name efficiently

Currently, I am facing an issue with my code where the | . [ ] part seems to be unnecessary. I would greatly appreciate any insights on how I can eliminate this code segment - it would be helpful if you could provide an explanation for why it is inefficie ...

NextJS - Error: Invalid JSON format, starting with a "<" symbol at position 0

After following a tutorial on NextJS, I attempted to make some modifications. My goal was to include the data.json file on the page. However, I kept encountering the error message "Unexpected token < in JSON at position 0." I understand that I need to con ...

Storing a JSON array in a MySQL (5.6) database - Which data type to use?

In MySQL version 5.6, when the JSON data type is not available, what would be the most suitable data type for storing a JSON encoded array? Currently considering using either TEXT or VARCHAR. Is this the correct approach for storing JSON data in this scen ...

Inconsistency in date serialization using JSON.stringify across various web browsers

I've written this snippet in an HTML file: alert(JSON.stringify(new Date())); To cater to older browsers lacking JSON.stringify(), I've included the latest json2.js (2009-09-29 version) along with jquery-1.3.2.js. In modern browsers with native ...

Using Java lambda expressions for regular expressions is a powerful tool that can help streamline your code

The code snippet below demonstrates extracting elements from a list and splitting the text after encountering a "(". for (WebElement element : measureKeys) { String[] measure = element.getText().split("\\("); testing.add(measure[0]) } A ...