Home > Blockchain >  "Unsupported Media Type" when i tried to send HTTP requests from Postman
"Unsupported Media Type" when i tried to send HTTP requests from Postman

Time:10-18

When I tried to HTTP requests I get "Unsupported Media Type" problem I tried so my ways from others solutuins but it cannot help. I tried wrote same code again from scratch butit happend again.

When I tried to HTTP requests I get "Unsupported Media Type" problem This is headers part of my Postman

My service

@Service
@RequiredArgsConstructor
public class MarkaService {
    private final MarkaRepository markaRepository;
    private final MarkaMapper markaMapper;

    public MarkaDto markaAdd(Marka marka) {
        Marka marka1=markaRepository.save(marka);
        return markaMapper.markaToDto(marka1);
    }
}

my controller

@RestController
@AllArgsConstructor
@RequestMapping("/rentCar")
public class MarkaController {

    private final MarkaService markaService;

    @PostMapping("/addMarka")
    public MarkaDto addMarka(@RequestBody Marka marka) {
        return markaService.markaAdd(marka);
    }

}

marka class

@Entity
@Data
@Table
@AllArgsConstructor
@RequiredArgsConstructor
public class Marka {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_marka_gen")
    @SequenceGenerator(name = "seq_marka_gen", sequenceName = "seq_marka_id", allocationSize = 1)
    //@Column(name = "id", nullable = false)
    private Long id;
    private String markaName;
    private boolean markaStatus;


    @OneToMany(fetch = FetchType.LAZY, mappedBy = "marka")
    @JsonBackReference
    private Set<Model> models;

//    private List<Model> models;
    @Override
    public String toString() {
        return "Marka [id="   id   ", Marka Name="   markaName   "]";
    }
}

CodePudding user response:

In your @PostMapping annotation specify what type it consumes. Here is an example:

@PostMapping(value ="/saveUser", consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE)

CodePudding user response:

Try to add @Consumes annotation above your method MarkaDto:

@PostMapping("/addMarka")
@Consumes(MediaType.APPLICATION_JSON)
public MarkaDto addMarka(@RequestBody Marka marka) {
   return markaService.markaAdd(marka);
}
  • Related