Exclude column from resultset in controller | Spring data jpa
<p>I have a Users Entity:</p>

<pre><code>public class SpringUsers implements Serializable {
    private String password;
    // other fields omitted
    @Basic
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
</code></pre>

<p>And its repository:</p>

<pre><code>public interface SpringUsersRepository extends CrudRepository&lt;SpringUsers, Integer&gt; {
    SpringUsers findByUsername(String username);
    List&lt;SpringUsers&gt; findByUserId(Integer userId);
}
</code></pre>

<p>And I have a controller method that should get a list of all registered users with the same userId (is internally used) as the currently authenticated user:</p>

<pre><code>public List&lt;SpringUsers&gt; getRegisteredUsers() {
    CustomUserDetails authenticatedUserDetails = getCustomUserDetails();
    List&lt;SpringUsers&gt; registered = springUsersRepository.findByUserId(
        authenticatedUserDetails.getUserMyId());
    return registered.stream().map(v -&gt; {
        v.setPassword(null);
        return v;
    }).collect(Collectors.toList());
}
</code></pre>

<p>I don't want to pass the password (even though it's encrypted) to the frontend - so I stream through the users and set the password to null, as you can see above. </p>

<p>However, I'm wondering if there isn't a possibility to just not include the users' password in the query result in the first place?</p>

<hr>

<p>Version Info:</p>

<p>Spring boot 1.4.0 &amp;
Hibernate 5.0.9.Final</p>