Home > database >  Postman shows error 500 cuz Object in JSON is null
Postman shows error 500 cuz Object in JSON is null

Time:12-20

So, I've got a Spring Application that saves books and authors. Author has Long id, String name. Book has Long id, String name and object of class Author author. In JSON it has to be like

 {
    "name": "Rich dad",
    "authorDto": {
        "id":2
    }
    }

So When I try to send the GET request for bookList I've got next message of error:

Cannot invoke "kg.istschool.bookservice.model.entity.Author.getId()" because "author" is null
    at kg.istschool.bookservice.mappers.AuthorMapper.authorToAuthorDto(AuthorMapper.java:27) ~[classes/:na]
    at kg.istschool.bookservice.mappers.BookMapper.bookToBookDto(BookMapper.java:45) ~[classes/:na]

Here is the link for the project: enter image description here

check your database table! is it there! Why this much needed for ID you can put @ID and @GeneratedValue(strategy = GenerationType.AUTO)

Not need of this code @Id @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "author_seq" ) @SequenceGenerator( name = "authors_seq", sequenceName = "author_sequence", initialValue = 1, allocationSize = 50 )

  • Related