Shan Menaka
Shan Menaka

Reputation: 41

Failed to evaluate Jackson deserialization in spring boot api

package lk.andunaechomedia.models;

import com.fasterxml.jackson.annotation.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import java.util.Date;


@Entity
public  class Device {
    @Id
    private String device_id;
    private String customer_name;
    private String start_point;
    private String end_point;
    private String device_address;
    private String tel_number;
    private Date   publish_date;
    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name="device_group_group_id")
    private Device_group device_group;

    public Device() {
    }

    public Device(String device_id,String customer_name,String start_point, String end_points, String device_address, String tel_number, Date publish_date) {
        this.setDevice_id(device_id);
        this.setCustomer_name(customer_name);
        this.setStart_point(start_point);
        this.setEnd_point(end_points);
        this.setDevice_address(device_address);
        this.setTel_number(tel_number);
        this.setPublish_date(publish_date);

    }

    public Device_group getDevice_group() {
        return device_group;
    }

    public void setDevice_group(Device_group device_group) {
        this.device_group = device_group;
    }

    public String getDevice_id() {
        return device_id;
    }

    public void setDevice_id(String device_id) {
        this.device_id = device_id;
    }

    public String getCustomer_name() {
        return customer_name;
    }

    public void setCustomer_name(String customer_name) {
        this.customer_name = customer_name;
    }

    public String getStart_point() {
        return start_point;
    }

    public void setStart_point(String start_point) {
        this.start_point = start_point;
    }

    public String getEnd_point() {
        return end_point;
    }

    public void setEnd_point(String end_point) {
        this.end_point = end_point;
    }

    public String getDevice_address() {
        return device_address;
    }

    public void setDevice_address(String address) {
        this.device_address = address;
    }

    public String getTel_number() {
        return tel_number;
    }

    public void setTel_number(String telphone) {
        this.tel_number = telphone;
    }

    public Date getPublish_date() {
        return publish_date;
    }

    public void setPublish_date(Date publish_date) {
        this.publish_date = publish_date;
    }

    /*public void updatePartial(Device device, String deice_id){
        Device newDevice = deviceRepo.findOne(device_id);
        if (device.getCustomer_name() != null){
            newDevice.setCustomer_name(device.getCustomer_name());
        }
        if (device.getStart_point() != null){
            newDevice.setStart_point(device.getStart_point());
        }
        if (device.getEnd_point() != null){
            newDevice.setEnd_point(device.getEnd_point());
        }
        if (device.getDevice_address() != null){
            newDevice.setDevice_address(device.getDevice_address());
        }
        if (device.getTel_number() != null){
            newDevice.setTel_number(device.getTel_number());
        }
        if (device.getPublish_date() != null){
            newDevice.setPublish_date(device.getPublish_date());
        }
    }*/


}




package lk.andunaechomedia.models;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.util.Set;

@Entity
public class Device_group {
   @Id
    private String group_id;
    private String group_name;
    @OneToMany(mappedBy = "device_group")
    private Set<Device> devices;
    @ManyToOne
    @JoinColumn(name="device_group_group_id", nullable=false)

    private Main_schedule main_schedule;
    private String temp_schedule_temp_id;
    @JsonBackReference(value="user-movement")
    public Set<Device> getDevice() {
        return devices;
    }

    public void setDevice(Set<Device> devices) {
        this.devices = devices;
    }

    public String getGroup_id(){ return group_id; }
     public void setGroup_id(String group_id){
      this.group_id=group_id;
     }

    public String getGroup_name(){
      return group_name;
     }
    public void setGroup_name(String group_name){
      this.group_name=group_name;
     }
    @JsonBackReference(value="user-movement")
    public Main_schedule getMain_schedule_schedule_id(){
      return main_schedule;
     }
    public void setMain_schedule_schedule_id(Main_schedule main_schedule){
      this.main_schedule=main_schedule;
     }

    public String getTemp_schedule_temp_id(){
      return temp_schedule_temp_id;
     }
    public void setTemp_schedule_temp_id(String temp_schedule_temp_id){
      this.temp_schedule_temp_id=temp_schedule_temp_id;
     }
}

this is error 20-01-22 Wed 14:17:56.475 WARN MappingJackson2HttpMessageConverter Failed to evaluate Jackson deserialization for type [[simple type, class lk.andunaechomedia.models.Device]]: com.fasterxml.jackson.databind.JsonMappingException: Multiple back-reference properties with name 'user-movement' 20-01-22 Wed 14:17:56.475 WARN DefaultHandlerExceptionResolver Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported]

this is my request body { "device_id":"bus009", "customer_name":"anura", "start_point":"matara", "end_point":"colombo", "device_address":"dikwella", "tel_number":"0712345678", "publish_date":"2020-10-10", "device_group":"138-Bus" }

Upvotes: 1

Views: 7207

Answers (2)

Muzaffar Umar
Muzaffar Umar

Reputation: 26

 @JsonBackReference  
   @OneToMany(fetch=FetchType.LAZY,  
     mappedBy = "device_group" 
       cascade=cascadeType.PERSIST)  
       private Set<Device> devices; 


 @JsonManagedReference    
     @ManyToOne(fetch=FetchType.LAZY)  
        @JoinColumn(name="device_group_group_id")  
        private Device_group device_group;



Upvotes: 0

Joe W
Joe W

Reputation: 2891

You reference the name user-movement more than once in your object tree as @JsonBackReference. You'll need to rename one of them. The two cases are:

@JsonBackReference(value="user-movement")
    public Set<Device> getDevice() {
        return devices;
    }

And

@JsonBackReference(value="user-movement")
    public Main_schedule getMain_schedule_schedule_id(){
      return main_schedule;
     }

See more: Jackson: Multiple back-reference properties with name 'defaultReference'

Upvotes: 3

Related Questions