I am working through a tutorial that involves creating a REST API with Spring Boot. I have a table called "book" in my database and have created the corresponding entity class (Book.java) and repository (BookRepository.java). When I call the REST API via my browser, I get different results based on whether I run the application on my Mac versus on my PC.
When I run the application and hit the endpoint on my Mac (localhost:8000/api/books), my response looks something like this:
{"_embedded" : {"books" : [ {"_links" : {"self" : {"href" : "http://localhost:8080/api/books/1" },"book" : {"href" : "http://localhost:8080/api/books/1" } } }, {"_links" : {"self" : {"href" : "http://localhost:8080/api/books/2" },"book" : {"href" : "http://localhost:8080/api/books/2" } }
This is my entity class:
@Entity@Table(name = "book")@Datapublic class Book { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "title") private String title; @Column(name = "author") private String author; @Column(name = "description") private String description; @Column(name = "copies") private int copies; @Column(name = "copies_available") private int copiesAvailable; @Column(name = "category") private String category; @Column(name = "img") private String img;}
This is my repository interface:
import org.springframework.data.jpa.repository.JpaRepository;import com.luv2code.springbootlibrary.entity.Book;public interface BookRepository extends JpaRepository<Book, Long>{}
When I run the application and hit the endpoint on my PC, my response looks like what I'd expect. I don't have a screenshot but the JSON lists the author, title, etc for each book instead of all those links shown in the response above.
Why would it return different things based on which device I'm running my application on? The project is exactly the same on both systems. I'd much rather prefer what I see when I run it on the PC but on my Mac instead... How can I obtain the format I desire on my Mac?
I've tried adding these entries to my properties file but it didn't fix the issue, though I'm still confused as to why I'd need to do anything different just for the response on my Mac to mimic the response on my PC.
spring.hateoas.use-hal-as-default-json-media-type=false
spring.data.rest.default-media-type=application/json