Fairly new Spring Developer here..
I've been using Spring for the last couple of days and managed to create a simple CRUD API using JPA and Spring Rest. Now, I want to have the flexibility of changing how the returned JSON is composed.
For example, I've got the following simple entity:
Table Name: Category
- category_id
- category_name
A GET request is returning the following JSON:
{
categoryName: "Category 1",
_links: {
self: {
href: "http://localhost:8080/faqsCategories/1"
},
faqsCategory: {
href: "http://localhost:8080/faqsCategories/1"
},
faqsContent: {
href: "http://localhost:8080/faqsCategories/1/faqsContent"
}
}
}
Now I want to remove the _links
part and add additional content..
Is this possible in Spring?
Classes:
FaqsCategory (Entity)
@Entity
@Table(name = "faqs_category")
public class FaqsCategory {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long categoryId;
private String categoryName;
@OneToMany(targetEntity = FaqsContent.class, mappedBy = "faqsCategory")
private Set<FaqsContent> faqsContent = new HashSet<>();
protected FaqsCategory() {
}
.....
}
FaqsCategoryRepository
@RepositoryRestResource
public interface FaqsCategoryRepository extends JpaRepository<FaqsCategory, Long> {
}