Announcement Announcement Module
Collapse
No announcement yet.
Filtering properties for Json Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filtering properties for Json

    I'm traying to filter a property of a POJO when converting it to Json:

    POJO:

    public class City {
    private Long id;
    private String name;
    private State state;


    public Long getId()
    {
    return id;
    }

    public void setId(Long id)
    {
    this.id = id;
    }

    public String getName()
    {
    return name;
    }

    public void setName(String name)
    {
    this.name = name;
    }

    public State getState()
    {
    return state;
    }

    public void setState(State state)
    {
    this.state = state;
    }
    }

    MixIn:

    @JsonAutoDetect(value = JsonMethod.NONE)
    public interface CityView
    {
    @JsonProperty("id")
    Long getId();

    @JsonProperty("name")
    String getName();

    @JsonIgnore
    State getState();
    }


    Controller:

    @RequestMapping(params = "viewCities", value = URLPaths.REGISTER, method = RequestMethod.POST)
    public @ResponseBody
    ModelAndView viewCitiesList(HttpServletRequest request)
    {
    String stateId = request.getParameter("stateCode");

    List cities = new ArrayList();
    ModelAndView modelAndView = new ModelAndView("jsonView");

    try
    {
    cities = this.entityManagementLogic.getCitiesByStates(state Id);

    ObjectMapper mapper = new ObjectMapper();
    MappingJacksonJsonView view = new MappingJacksonJsonView();

    mapper.getSerializationConfig().addMixInAnnotation s(City.class,
    CityView.class);

    view.setObjectMapper(mapper);

    modelAndView.setView(view);

    modelAndView.addObject(cities);

    }
    catch(Exception e)
    {

    }
    return modelAndView;
    }

    xml:

    <!-- json view, capable of converting any POJO to json format -->
    <bean id="jsonView"
    class="org.springframework.web.servlet.view.json.M appingJacksonJsonView" />

    I always get the property state, somebody know why is this not working? Thank you so much
Working...
X