I have to entities exposed by spring boot application powered by Spring data REST.
@Entity
@Table(name = "joke")
@Data
public class Joke {
@Id
@Column(name = "joke_id")
private Long id;
@Column(name = "content")
private String content;
@JsonProperty("category")
@JoinColumn(name = "category_fk")
@ManyToOne(fetch = FetchType.EAGER)
private Category category;
}
and category
@Entity
@Table(name = "category")
@Data
public class Category {
@Id
@Column(name = "category_id")
private int id;
@Column(name = "name")
private String name;
}
It is working fine and exposing the HAL+Json format. I'm using Traverson client which is working fine:
Traverson client = new Traverson(URI.create("http://localhost:8080/api/"),
MediaTypes.HAL_JSON);
HashMap<String, Object> parameters = Maps.newHashMap();
parameters.put("size", "2");
PagedModel<JokesDTO> jokes = client
.follow("jokes")
.withTemplateParameters(parameters)
.toObject(new PagedModelType<JokesDTO>() {
});
return jokes;
where JokesDTO is:
@Builder(toBuilder = true)
@Value
@JsonDeserialize(builder = JokesDTO.JokesDTOBuilder.class)
@JsonInclude(Include.NON_NULL)
public class JokesDTO {
private String content;
@JsonPOJOBuilder(withPrefix = "")
@JsonIgnoreProperties(ignoreUnknown = true)
public static class JokesDTOBuilder {
}
}
I'm new in HAL and HateOS and I would like to achieve 2 things (and question is - is it possible, and how):
Base on
Traverson clientcall, how to retrieve category (or link to category) in one call? How to extend what I wrote. And I'm not talking about adding additional@JsonPropertyannotation to my class definition.Is it possible to expose the inner query from Spring data REST, so I would be able to get all data with one call, is it possible with @RepositoryRestResource?