2

I have created the rest controller using spring-boot and apache cxf-rs, which returns the Page (org.springframework.data.domain.Page) with the entities. My problem is that Page in xml formal returns only Content with entities, without metadata (pageable, sort...). In json format all works fine - Page is dysplayed Content and metadata.

import org.springframework.data.domain.jaxb.PageAdapter;

    @GET
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @XmlJavaTypeAdapter(PageAdapter.class)
    Page<Monitor> getAllMonitors(@PathParam("page") int page, 
        @PathParam("size") int size){
        Pageable pageable = PageRequest.of(page, size);
        return repository.findAll(pageable);
    }

In config class I have a Bean for XML, provided by cxf-rs:

    @Bean
    public JAXBElementProvider jaxbElementProvider(){
        JAXBElementProvider jaxbElementProvider = new JAXBElementProvider();
        jaxbElementProvider.setSingleJaxbContext(true);
        jaxbElementProvider.setExtraClass(new Class[] {Monitor.class});
        return jaxbElementProvider;
    }

I expect to see the page like this:

<sd:page xmlns:sd="http://www.springframework.org/schema/data/jaxb" xmlns:atom="http://www.w3.org/2005/Atom">
  <content>
    <Monitor>
    ... content
    </Monitor>
  </content>
  <pageable>
  ...
  </pageable>
  <sort>
  ...
  </sort>
  <totalElements>...</totalElements>
  <numberOfElements>...</numberOfElements>
</sd:page>

But I receive page only with content:

<sd:page xmlns:sd="http://www.springframework.org/schema/data/jaxb" xmlns:atom="http://www.w3.org/2005/Atom">
  <content>
    <Monitor>
    ... content
    </Monitor>
  </content>
</sd:page>

What should I do for displaying full Page in xml format? Thanks for any help!

Tharif
  • 13,794
  • 9
  • 55
  • 77
E_Lis
  • 21
  • 2

0 Answers0