0

My API started returning such JSONs:

{
  "links": [
    {
      "rel": "self",
      "href": "http://127.0.0.1:8888/books/4/instances"
    }
  ],
  "content": [
    {
      "donatorName": "Lee Anderson",
      "content": [],
      "links": [
        {
          "rel": "self",
          "href": "http://127.0.0.1:8888/book-instances/4"
        },
        {
          "rel": "bookInstance",
          "href": "http://127.0.0.1:8888/book-instances/4"
        },
        {
          "rel": "reservations",
          "href": "http://127.0.0.1:8888/book-instances/4/reservations"
        },
        {
          "rel": "library",
          "href": "http://127.0.0.1:8888/book-instances/4/library"
        },
        {
          "rel": "book",
          "href": "http://127.0.0.1:8888/book-instances/4/book"
        }
      ]
    },
    {
      "donatorName": "Leroy Guerrero",
      "content": [],
      "links": [
        {
          "rel": "self",
          "href": "http://127.0.0.1:8888/book-instances/5"
        },
        {
          "rel": "bookInstance",
          "href": "http://127.0.0.1:8888/book-instances/5"
        },
        {
          "rel": "reservations",
          "href": "http://127.0.0.1:8888/book-instances/5/reservations"
        },
        {
          "rel": "library",
          "href": "http://127.0.0.1:8888/book-instances/5/library"
        },
        {
          "rel": "book",
          "href": "http://127.0.0.1:8888/book-instances/5/book"
        }
      ]
    }
  ]
}

This is not hal+json, I couldn't find the convention that uses "content" and "links"(without underscore) fields. What am I doing wrong? I want "_links" and "embedded".

My pom.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo2</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

My repositories are simple PagingAndSortingRepository classes.

package demo;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
//import org.springframework.hateoas.PagedResources;

@RepositoryRestResource(collectionResourceRel = "libraries", path = "libraries")
public interface LibraryRepository extends PagingAndSortingRepository<Library, Long> {

}

What am I missing out? Or including more than I need?

EralpB
  • 1,621
  • 4
  • 23
  • 36

1 Answers1

0

Okay it is because I added "spring.data.rest.defaultMediaType=application/xml" to the application.properties. Gotta love the magic.

EralpB
  • 1,621
  • 4
  • 23
  • 36