JsonView not working correctly with Spring
<p>I'm using Spring boot to create a restful api service. Everything works correctly, except that I cannot specify which data to be returned as JSON.</p>

<p>What I want is to get the output without the field "content" ( which in my case is used for storing the object ).</p>

<p>Spring version is 4.2.5</p>

<p>That's why I've defined 3 levels of views ( Internal being the one to be used when getting / setting object in the database, Public is the minimal data to be output to client ):</p>

<pre><code>public class EntityVisibility {
    public static class Public { }
    public static class Detailed extends Public { }
    public static class Internal extends Detailed { }
}
</code></pre>

<p>My controller:</p>

<pre><code>@RestController
@RequestMapping("/api/photos")
public class PhotoController extends BaseController {

    @JsonView(EntityVisibility.Public.class)
    @RequestMapping(value="/load", method= RequestMethod.GET)
    public Response&lt;Photo&gt; loadFromUrl(@RequestParam("url") String urlAddress) {

        Photo photo = ...; // create photo object

        return new Response&lt;&gt;(photo);
    }
}
</code></pre>

<p>To me, it looks that <code>@JsonView(EntityVisibility.Public.class)</code> is now working.</p>

<p>Response class (only relevant parts):</p>

<pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response&lt;T&gt; {

private T result;

    public Response(T response) {
        result = response;
    }


}
</code></pre>

<p>My Photo class (relevant parts):</p>

<pre><code>public class Photo extends Entity {

    @JsonIgnore
    protected byte[] content;

    @JsonView(EntityVisibility.Public.class)
    private Date modified;

    @JsonProperty("content")
    @JsonView(EntityVisibility.Internal.class)
    public void setB64content(String b64content) {
        this.content = (b64content == null) ? null : Base64.decode(b64content.getBytes());
    }

    public String getB64content() {

        try {
            return (content.length == 0) ? null : new String(Base64.encode(content), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }

    public byte[] getContent() {
        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

}
</code></pre>

<p>Entity class (relevant parts): </p>

<pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
public class Entity {

}
</code></pre>

<p>What I'm getting:</p>

<p><code>{"success":true,"result":{"mime_type":"image/png","content":"SOME_CONTENT_HERE"}}</code></p>

<p>Expected result:</p>

<p><code>{"success":true,"result":{"mime_type":"image/png"}}</code></p>

<p>Any help is greatly appreciated!</p>

<p>== EDIT ==</p>

<p>I've created new very simple setup, but it's still not working for me:</p>

<p>Method in the @RestController:</p>

<pre><code>@JsonView(EntityVisibility.Public.class)
@RequestMapping(value="/test", method= RequestMethod.GET)
public Response&lt;TestObject&gt; testMethos() {

    TestObject testObject = new TestObject();
    testObject.setTest1("test1");
    testObject.setTest2("test2");
    testObject.setTest3("test3");

    return new Response&lt;&gt;(testObject);
}
</code></pre>

<p>The test class:</p>

<pre><code>public class TestObject {

    @JsonView(EntityVisibility.Public.class)
    private String test1;

    @JsonView(EntityVisibility.Detailed.class)
    private String test2;

    @JsonView(EntityVisibility.Internal.class)
    private String test3;

    @JsonIgnore
    private String test4;


    public String getTest1() {
        return test1;
    }

    public void setTest1(String test1) {
        this.test1 = test1;
    }

    public String getTest2() {
        return test2;
    }

    public void setTest2(String test2) {
        this.test2 = test2;
    }

    public String getTest3() {
        return test3;
    }

    public void setTest3(String test3) {
        this.test3 = test3;
    }

    public String getTest4() {
        return test4;
    }

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

<p>My pom.xml (full):</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;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"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;ch.sumli&lt;/groupId&gt;
    &lt;artifactId&gt;SumliCore&lt;/artifactId&gt;
    &lt;version&gt;0.1&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;

    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
    &lt;/parent&gt;

    &lt;dependencies&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;com.couchbase.client&lt;/groupId&gt;
            &lt;artifactId&gt;java-client&lt;/artifactId&gt;
            &lt;version&gt;2.2.6&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
            &lt;version&gt;4.0.4.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
            &lt;version&gt;4.0.4.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
            &lt;version&gt;4.0.4.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
            &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
            &lt;version&gt;5.2.2.Final&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;jmimemagic&lt;/groupId&gt;
            &lt;artifactId&gt;jmimemagic&lt;/artifactId&gt;
            &lt;version&gt;0.1.2&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.imgscalr&lt;/groupId&gt;
            &lt;artifactId&gt;imgscalr-lib&lt;/artifactId&gt;
            &lt;version&gt;4.2&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.quartz-scheduler&lt;/groupId&gt;
            &lt;artifactId&gt;quartz&lt;/artifactId&gt;
            &lt;version&gt;2.2.2&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.quartz-scheduler&lt;/groupId&gt;
            &lt;artifactId&gt;quartz-jobs&lt;/artifactId&gt;
            &lt;version&gt;2.2.2&lt;/version&gt;
        &lt;/dependency&gt;

    &lt;/dependencies&gt;

    &lt;properties&gt;
        &lt;start-class&gt;ch.sumli.Application&lt;/start-class&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
        &lt;java.version&gt;1.7&lt;/java.version&gt;
    &lt;/properties&gt;

    &lt;repositories&gt;
        &lt;repository&gt;
            &lt;id&gt;couchbase&lt;/id&gt;
            &lt;name&gt;couchbase repo&lt;/name&gt;
            &lt;url&gt;http://files.couchbase.com/maven2&lt;/url&gt;
            &lt;snapshots&gt;&lt;enabled&gt;false&lt;/enabled&gt;&lt;/snapshots&gt;
        &lt;/repository&gt;
    &lt;/repositories&gt;

    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

&lt;/project&gt;
</code></pre>

<p>And I'm still getting everything ( except for <code>@JsonIgnore</code> ):</p>

<pre><code>{"success":true,"result":{"test1":"test1","test2":"test2","test3":"test3"}}
</code></pre>