could anyone tell me why i see only values not properties:value in my JSON. I am using below code
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/search")
PagedResources<Resource<Order>> search(@Valid OrderSearch search,
@SortDefault(sort = "poNumber", direction = DESC) Pageable pageable) {
Page<Order> orders = orderService.searchOrders(search, pageable);
return pagedAssembler.toResource(orders);
}
Also i am not seeing any links, any idea if i am missing any configuration, Here is the JSON output
{"links":[],"content":[{"links":[],"content":["1000","100",100,"ACTIVE","ARROW","New York",1424980115000,null,"NY",null,"New York"],"id":null},
{"links":[],"content":["10001","100",100,"ACTIVE","Pivotal","Massachusetts",1425013200000,null,"MA",null,"Massachusetts"],"id":null}],
"metadata":{"size":10,"totalElements":2,"totalPages":1,"number":0},"nextLink":null,"previousLink":null,"id":null}
And here is another way i did based on your explanation at
[How to correctly use PagedResourcesAssembler from Spring Data?
OrderResourceAssembler.java
public class OrderResourceAssembler extends ResourceAssemblerSupport {
public OrderResourceAssembler() {
super(OrderController.class, OrderResource.class);
}
/**
* @see org.springframework.hateoas.ResourceAssembler#toResource(java.lang.Object)
*/
@Override
public OrderResource toResource(Order entity) {
OrderResource orderResource = null;
if (entity != null) {
orderResource = createResourceWithId(
entity.getPurchaseOrderNumber(), entity);
orderResource.setPurchaseOrderNumber(entity
.getPurchaseOrderNumber());
orderResource.setAmount(entity.getAmount());
orderResource.setEndUser(entity.getEndUser());
orderResource.setPartner(entity.getPartner());
orderResource.setPayload(entity.getPayload());
orderResource.setProcessStatus(entity.getProcessStatus());
orderResource.setQuoteNumber(entity.getQuoteNumber());
orderResource.setQuoteStatus(entity.getQuoteStatus());
orderResource.setReceivedDate(entity.getReceivedDate());
orderResource.setRegion(entity.getRegion());
orderResource.setSalesOrderNumber(entity.getSalesOrderNumber());
orderResource.setShipTo(entity.getShipTo());
orderResource.setShipToCustomer(entity.getShipToCustomer());
orderResource.setType(entity.getType());
}
return orderResource;
}
2. OrderResource extends ResourceSupport
OrderController.java
public class OrderController {
@Autowired private OrderService orderService; @Autowired private OrderResourceAssembler orderAssembler; @Autowired private PagedResourcesAssembler<Order> pagedAssembler;
@RequestMapping(method = RequestMethod.GET, value = "/search") @ResponseBody PagedResources search( @Valid OrderSearch search, @PageableDefault(page = 1, value = Integer.MAX_VALUE) @SortDefault(sort = "poNumber", direction = Sort.Direction.DESC) Pageable pageable) { Page orders = orderService.searchOrders(search, pageable); return pagedAssembler.toResource(orders, orderAssembler); } }
When i try to hit the url, repository query gets executed but i get ClassCastException
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.mycomp.it.channeltracker.model.Order at com.mycomp.it.eis.channeltracker.api.resource.OrderResourceAssembler.toResource(OrderResourceAssembler.java:8) at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:122) at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:93) at com.emc.it.eis.channeltracker.api.OrderController.search1(OrderController.java:89)
Not sure what the issue is, And here is my servlet config
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean
class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService" ref="conversionService" />
</bean>
</property>
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
<property name="customArgumentResolvers">
<list>
<bean class="org.springframework.data.web.PageableArgumentResolver" />
</list>
</property>
</bean>
<bean id= "conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
<bean class="org.springframework.data.web.PagedResourcesAssembler">
<constructor-arg>
<bean class="org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver" />
</constructor-arg>
<constructor-arg>
<null />
</constructor-arg>
</bean>
<bean class="org.springframework.data.web.config.SpringDataWebConfiguration" />
and bean config for OrderResourceAssembler
class="com.mycomp.it.eis.channeltracker.api.resource.OrderResourceAssembler"/>
could you please provide me your inputs on what's missing