spring-hateoas

How to write a mockito test case for ResourceAssembler with in Spring Hateos?

回眸只為那壹抹淺笑 提交于 2019-12-24 06:03:58
问题 I am trying to write a unit test for the below Assembler but i keep getting Could not find current request via RequestContextHolder. Is this being called from a Spring MVC handler? . I wanted to know how i can mock out the resource creation? @Component public class LoginResourceAssembler extends ResourceAssemblerSupport<User, ResourceSupport> { public LoginResourceAssembler() { super(User.class, ResourceSupport.class); } @Override public ResourceSupport toResource(User user) { ResourceSupport

How to write a mockito test case for ResourceAssembler with in Spring Hateos?

左心房为你撑大大i 提交于 2019-12-24 06:03:12
问题 I am trying to write a unit test for the below Assembler but i keep getting Could not find current request via RequestContextHolder. Is this being called from a Spring MVC handler? . I wanted to know how i can mock out the resource creation? @Component public class LoginResourceAssembler extends ResourceAssemblerSupport<User, ResourceSupport> { public LoginResourceAssembler() { super(User.class, ResourceSupport.class); } @Override public ResourceSupport toResource(User user) { ResourceSupport

Embed object instead of collection in Spring HATEOAS

一世执手 提交于 2019-12-24 00:12:46
问题 A very quick question ,to which there seems to be no easy answer. Is it possible to put an object directly under the embedded resources using Spring HATEOAS? The desired output format in JSON should look like { ... _embedded: { myObject: { ... } } } Using the code below, I always end up with a colletion for any resource I want to embed. ArrayList<Resource<?>> embeddedContent = new ArrayList<>(); Resource<MyObject> myObjectResource = new Resource<MyObject>(new MyObject()); embeddedContent.add

HATEOAS and forms driven by the API

半城伤御伤魂 提交于 2019-12-23 12:26:54
问题 I'm trying to apply HATEOAS to the existing application and I'm having trouble with modeling a form inputs that would be driven by the API response. The app is allowing to search & book connections between two places. First endpoint allows for searching the connections GET /connections?from={lat,lon}&to={lat,lon}&departure={dateTime} and returns following payload (response body). [ { "id": "aaa", "carrier": "Fast Bus", "price": 3.20, "departure": "2019-04-05T12:30" }, { "id": "bbb", "carrier"

Spring hateoas xml serialization for list of resources built with ResourceAssemblerSupport

江枫思渺然 提交于 2019-12-23 05:55:19
问题 I am trying to support XML responses for my Spring HATEOAS based application. JSON responses work fine as well as XML for a single resource. The problem starts with the list of the resources. Spring MVC controller cannot serialize the list built with help of ResourceAssemblerSupport derived class. The controller throws "org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation" for the curl command curl -k -i -H "Accept:application/xml" -H "Media

Spring Data Rest: custom Converter<Entity, Resource> is never invoked

让人想犯罪 __ 提交于 2019-12-23 02:07:23
问题 I'm trying to implement a custom Converter for an Entity to a Resource object with Spring Data Rest, but the Converter is never invoked. I'm following this documentation: If your project needs to have output in a different format, however, it’s possible to completely replace the default outgoing JSON representation with your own. If you register your own ConversionService in the ApplicationContext and register your own Converter, then you can return a Resource implementation of your choosing.

How to write paginated controller that expose resource or list of resource in spring-data-hatoas

一曲冷凌霜 提交于 2019-12-22 13:32:52
问题 Using spring-data, I want to write two method for my Person entity. Person.java: public class Person { @Id String id; String name; Integer age; // getters/setters omitted for clarity } I have written also a PersonResouce : public class PersonResource extends Resource<Person> { public PersonResource(Person content, Link... links) { super(content, links); } } I have also added a PersonResourceAssembler : public class PersonResourceAssembler extends ResourceAssemblerSupport<Person,

How to write paginated controller that expose resource or list of resource in spring-data-hatoas

非 Y 不嫁゛ 提交于 2019-12-22 13:32:19
问题 Using spring-data, I want to write two method for my Person entity. Person.java: public class Person { @Id String id; String name; Integer age; // getters/setters omitted for clarity } I have written also a PersonResouce : public class PersonResource extends Resource<Person> { public PersonResource(Person content, Link... links) { super(content, links); } } I have also added a PersonResourceAssembler : public class PersonResourceAssembler extends ResourceAssemblerSupport<Person,

Spring Data Rest - PUT is not working for associated reference types?

江枫思渺然 提交于 2019-12-22 09:56:07
问题 I have the following domain class implemented for a Spring Data Rest project. @Entity @Data public class Address { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private long addressID; private String houseName; private String apartmentNumber; @ManyToOne private City city; @ManyToOne private Country country; } Now I am creating an Address resource by sending a POST with following JSON. { "houseName":"Some House", "apartmentNumber":"13 B", "city": "http:/

How to change the property name of an embbed collection in Spring Hateos

╄→尐↘猪︶ㄣ 提交于 2019-12-22 09:49:06
问题 I am using Spring hateoas to generate a HAL interface. My code looks like this: @RequestMapping(method = RequestMethod.GET) public Resources<Resource<Type>> all() { List<Resource<Type>> sdf = typeRepository.all().stream().map(type -> { return new Resource<Type>(type, ControllerLinkBuilder.linkTo(this.getClass()).slash(type.getId()).withSelfRel()); }).collect(Collectors.toList()); Resources<Resource<Type>> resourcesType = new Resources<>(sdf); resourcesType.add(ControllerLinkBuilder.linkTo