0

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": "admin@gmail.com",
        "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

A J
  • 1,439
  • 4
  • 25
  • 42
  • 2
    Does this answer your question? [415 unsupported media type angular spring boot POST PUT http methods](https://stackoverflow.com/questions/70308519/415-unsupported-media-type-angular-spring-boot-post-put-http-methods) – Faramarz Afzali Dec 10 '21 at 19:47
  • no it dosen't unfortunately, by the way i'm the same one who asked the other quetion – jesser dhieb Dec 10 '21 at 21:31
  • Read this! check your headers as said there and check the other posibilities https://stackoverflow.com/questions/50563593/content-type-application-jsoncharset-utf-8-not-supported-in-spring-rest-app – Hector Gutierrez Dec 10 '21 at 23:39
  • @HectorGutierrez i found the problem it was caused by `@JsonManagedReference` – jesser dhieb Dec 11 '21 at 09:50
  • @jesserdhieb if you got the solution... Please add the answer and mark as solution... great day! – Hector Gutierrez Dec 11 '21 at 18:07

1 Answers1

1

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