Note that there are some explanatory texts on larger screens.

plurals
  1. POJackson annotations being ignored in Spring
    primarykey
    data
    text
    <p>I'm trying to make a property in a domain class hidden but it keeps appearing in the outputted JSON. I'm using Jackson 2.0 and Spring 3.1.1</p> <p>Output of /users/1:</p> <pre><code>{"id":1,"password":null,"email":"someone@somewhere.com","firstName":"John","lastName":"Smith"} </code></pre> <p>My domain class:</p> <pre><code>@Entity public class User { private String mPassword; ... @JsonIgnore public String getPassword() { return mPassword; } public void setPassword(String password) { mPassword = password; } ... } </code></pre> <p>My springmvc config:</p> <pre><code>... &lt;mvc:annotation-driven/&gt; &lt;bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt; &lt;property name="favorPathExtension" value="true" /&gt; &lt;property name="mediaTypes"&gt; &lt;map&gt; &lt;entry key="json" value="application/json"/&gt; &lt;/map&gt; &lt;/property&gt; &lt;property name="defaultContentType" value="application/json"/&gt; &lt;property name="defaultViews"&gt; &lt;list&gt; &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; ... </code></pre> <p>And my controller:</p> <pre><code>@Controller @RequestMapping("/users") public class UserController { private UserService mUserService; public UserController(){} @Inject public void setUserController(UserService userService){ mUserService=userService; } @RequestMapping(value="/{id}", method=RequestMethod.GET) public void getUser(@PathVariable("id") long id, Model model){ model.addAttribute(mUserService.getUser(id)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload