Home > Software design >  415 http media type not supported exception PUT method Postman
415 http media type not supported exception PUT method Postman

Time:12-13

Hi guys i've been trying to solve this error in the last 2 days so my problem is that i want to call a PUT Rest api to change my user data, when i change the data then i send it i get this 415 error enter image description here the input in the body

 {
        "idUser": 1,
        "nom": "admin",
        "prenom": "dhieb",
        "dateNaissance": "2015-03-23",
        "email": "[email protected]",
        "password": "$2a$10$bFB3bOFWLR6I5A8u6UMdZer0hHW603XUiFGlP8HvyIx9jGhzF4tSa",
        "picture": null,
        "phoneNumber": null,
        "adresse": null,
        "role": [
            {
                "id": 1,
                "role": "ADMIN"
            }
        ],
        "facture": [],
        "avisUser": [],
        "profession": "Etudiant",
        "categorieUser": "Prenuim"
    }

my service Put http method Spring Boot Controller

//url=http://localhost:8090/SpringMVC/user/modify-user
@PutMapping("modify-user")
   @ResponseBody
   public User modifyUser(@RequestBody User u){
       return userService.updateUser(u);
   }

my service Put http method Spring Boot Service

public User updateUser(User u) {
        userRepository.save(u);
        return u;
    }

my User class Spring Boot Entity

@Entity
@Table
@Setter
@Getter
@NoArgsConstructor
@ToString
public class User implements Serializable {
    public User(String nom, String prenom, Date dateNaissance, String email, String password, CategorieUser categorieUser, Profession profession) {
        this.nom = nom;
        this.prenom = prenom;
        this.dateNaissance = dateNaissance;
        this.email = email;
        this.password = password;
        CategorieUser = categorieUser;
        Profession = profession;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="idUser")
    private Long idUser;
    private String nom;
    private String prenom;
    @Temporal(TemporalType.DATE)
    private Date dateNaissance;
    private String email;
    private String password;
    private CategorieUser CategorieUser;
    private Profession Profession;

    private String picture;
    private Integer phoneNumber;
    private String adresse;//test

    @ManyToMany(cascade = CascadeType.PERSIST,fetch = FetchType.EAGER)
    private Set<Role> role;

    @OneToMany(mappedBy = "user",cascade = CascadeType.ALL)
    private Set<Facture> facture;

    @OneToMany(mappedBy = "user_avis",cascade = CascadeType.ALL)
    private Set<AvisUser> avisUser;



}

here is the header here is the header

CodePudding user response:

the problem was caused by the annotation @JsonManagedReference in a class related to mine ,I removed it and everything worked fine

  • Related