0

I have the POST request API call to accept the JSON body request parameters and multipart file from the client side. This is my method:

@PostMapping("/saveCategory")
    @ResponseStatus(HttpStatus.OK)
    public void createCategory( @RequestParam("file") MultipartFile file,@RequestParam("cateogry") CategoryModel category) {
        String fileName = fileStorageService.storeFile(file);

        String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath().path("/downloadFile/")
                .path(fileName).toUriString();
        //category.setImage_path(fileName);

        //this.categoryRepository.save(category);

        // return new UploadFileResponse(fileName, fileDownloadUri,
        // file.getContentType(), file.getSize());

    }

I have this exception:

 "category_name": "ziska111"

    }'; nested exception is java.lang.NumberFormatException: For input string: "{"category_name":"ziska111"}"]

This is my Postman request: enter image description here

I think I have a problem with my CategoryModel but I do not know why: This is my CategoryModel:

   @Entity
   @Table(name = "Category")
   @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class CategoryModel {
    @Id
    @Column(name = "id")
//@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String category_name;
private String category_description;
private String image_path;

@JsonIgnore
@OneToMany( mappedBy = "category")
private Set<ProductModel> category;
+Geterrs and Setters
SIn san sun
  • 573
  • 4
  • 13
  • 31

1 Answers1

0

You try to convert string to integer but, input string contains alphabetical characters and it's impossible to convert to integer

nissim abehcera
  • 821
  • 6
  • 7
  • Hmm, how I can to send an object from my postman, not String? – SIn san sun Feb 25 '19 at 13:05
  • As I can see from your screen shot, you have selected category as text but you're passing data as Json. That might be the issue. Please check In the meantime, you can check the difference between two here : https://stackoverflow.com/questions/4350753/advantages-of-using-application-json-over-text-plain – Pawan Tiwari Feb 25 '19 at 13:15