title: Adding more information to the HATEOAS response in Spring Boot Data Rest
body: <p>I have the following REST controller.</p>
  
  <pre><code>@RepositoryRestController
  @RequestMapping(value = "/booksCustom")
  public class BooksController extends ResourceSupport {
  
      @Autowired
      public BooksService booksService;
  
      @Autowired
      private PagedResourcesAssembler&lt;Books&gt; booksAssembler;
  
      @RequestMapping("/search")
      public HttpEntity&lt;PagedResources&lt;Resource&lt;Books&gt;&gt;&gt; search(@RequestParam(value = "q", required = false) String query, @PageableDefault(page = 0, size = 20) Pageable pageable) {
          pageable = new PageRequest(0, 20);
  
          Page&lt;Books&gt; booksResult = BooksService.findBookText(query, pageable);
  
          return new ResponseEntity&lt;PagedResources&lt;Resource&lt;Books&gt;&gt;&gt;(BooksAssembler.toResource(BooksResult), HttpStatus.OK);
  
      }
  </code></pre>
  
  <p>My <code>Page&lt;Books&gt; BooksResult = BooksService.findBookText(query, pageable);</code> is backed by <code>SolrCrudRepository</code>. When it is run <code>BookResult</code> has several fields in it, the content field and several other fields, one being <code>highlighted</code>. Unfortunately the only thing I get back from the REST response is the data in the <code>content</code> field and the metadata information in the HATEOAS response (e.g. page information, links, etc.). What would be the proper way of adding the <code>highlighted</code> field to the response? I'm assuming I would need to modify the <code>ResponseEntity</code>, but unsure of the proper way.</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Model:</p>
  
  <pre><code>@SolrDocument(solrCoreName = "Books_Core")
  public class Books {
      @Field
      private String id;
  
      @Field
      private String filename;
  
      @Field("full_text")
      private String fullText;
  
      //Getters and setters omitted 
      ...
  }
  </code></pre>
  
  <p>When a search and the SolrRepository is called (e.g. BooksService.findBookText(query, pageable);) I get back these objects. </p>
  
  <p><a href="https://i.stack.imgur.com/gNVor.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gNVor.png" alt="enter image description here"></a></p>
  
  <p>However, in my REST response I only see the "content". I would like to be able to add the "highlighted" object to the REST response. It just appears that HATEOAS is only sending the information in the "content" object (see below for the object). </p>
  
  <pre><code>{
    "_embedded" : {
      "solrBooks" : [ {
        "filename" : "ABookName",
        "fullText" : "ABook Text"
      } ]
    },
    "_links" : {
      "first" : {
        "href" : "http://localhost:8080/booksCustom/search?q=ABook&amp;page=0&amp;size=20"
      },
      "self" : {
        "href" : "http://localhost:8080/booksCustom/search?q=ABook"
      },
      "next" : {
        "href" : "http://localhost:8080/booksCustom/search?q=ABook&amp;page=0&amp;size=20"
      },
      "last" : {
        "href" : "http://localhost:8080/booksCustom/search?q=ABook&amp;page=0&amp;size=20"
      }
    },
    "page" : {
      "size" : 1,
      "totalElements" : 1,
      "totalPages" : 1,
      "number" : 0
    }
  }
  </code></pre>
  
  <p>Just so you can get a full picture, this is the repository that is backing the BooksService. All the service does is call this SolrCrudRepository method. </p>
  
  <pre><code>public interface SolrBooksRepository extends SolrCrudRepository&lt;Books, String&gt; {
  
      @Highlight(prefix = "&lt;highlight&gt;", postfix = "&lt;/highlight&gt;", fragsize = 20, snipplets = 3)
      HighlightPage&lt;SolrTestDocuments&gt; findBookText(@Param("fullText") String fullText, Pageable pageable);
  
  }
  </code></pre>