Spring Hateoas ControllerLinkBuilder adds null fields : <p>I'm following a tutorial on Spring REST and am trying to add HATEOAS links to my Controller results.</p>

<p>I have a simple User class and a CRUD controller for it.</p>

<pre><code>class User {
    private int id;
    private String name;
    private LocalDate birthdate;
    // and getters/setters
}
</code></pre>

<p>Service:</p>

<pre><code>@Component
class UserService {
    private static List&lt;User&gt; users = new ArrayList&lt;&gt;();
    List&lt;User&gt; findAll() {
        return Collections.unmodifiableList(users);
    }
    public Optional&lt;User&gt; findById(int id) {
        return users.stream().filter(u -&gt; u.getId() == id).findFirst();
    }
    // and add and delete methods of course, but not important here
}
</code></pre>

<p>Everything works fine except in my Controller, I want to add links from the all user list to the single users:</p>

<pre><code>import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/users")
    public List&lt;Resource&lt;User&gt;&gt; getAllUsers() {
        List&lt;Resource&lt;User&gt;&gt; userResources = userService.findAll().stream()
            .map(u -&gt; new Resource&lt;&gt;(u, linkToSingleUser(u)))
            .collect(Collectors.toList());
        return userResources;
    }
    Link linkToSingleUser(User user) {
        return linkTo(methodOn(UserController.class)
                      .getById(user.getId()))
                      .withSelfRel();
    }
</code></pre>

<p>so that for every User in the result list, a link to the user itself is added.</p>

<p>The link itself is created fine, but there are superfluous entries in the resulting JSON:</p>

<pre><code>[
    {
        "id": 1,
        "name": "Adam",
        "birthdate": "2018-04-02",
        "links": [
            {
                "rel": "self",
                "href": "http://localhost:8080/users/1",
                "hreflang": null,
                "media": null,
                "title": null,
                "type": null,
                "deprecation": null
            }
        ]
    }
]
</code></pre>

<p>Where do the fields with null value (<code>hreflang</code>, <code>media</code> etc) come from and why are they added? Is there a way to get rid of them?</p>

<p>They do not appear when building a link to the all users list:</p>

<pre><code>@GetMapping("/users/{id}")
public Resource&lt;User&gt; getById(@PathVariable("id") int id) {
    final User user = userService.findById(id)
                                 .orElseThrow(() -&gt; new UserNotFoundException(id));
    Link linkToAll = linkTo(methodOn(UserController.class)
                            .getAllUsers())
                            .withRel("all-users");
    return new Resource&lt;User&gt;(user, linkToAll);
}
</code></pre>
