Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4554014
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:01:49+00:00 2026-05-21T17:01:49+00:00

I am using the following bean definition to make my spring app talking in

  • 0

I am using the following bean definition to make my spring app talking in JSON

<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />

Is it possible with this message converter bean to use the @JsonView annotation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:01:50+00:00Added an answer on May 21, 2026 at 5:01 pm

    @JsonView is already supported in the Jackson JSON Processor from v1.4 onwards.

    New Edit: Updated for Jackson 1.9.12

    According to the v1.8.4 documentation the function I was using writeValueUsingView is now Deprecated Use ObjectMapper.viewWriter(java.lang.Class) instead… however that has also been Deprecated Since 1.9, use writerWithView(Class) instead! (see v1.9.9 documentation)

    So here is an updated example, tested with Spring 3.2.0 and Jackson 1.9.12 which simply returns {id: 1} and not the extended {name: "name"} since it is using the .writerWithView(Views.Public.class). Switching to Views.ExtendPublic.class will result in {"id":1,"name":"name"}

    package com.demo.app;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import org.codehaus.jackson.map.annotate.JsonView;
    import org.codehaus.jackson.map.ObjectMapper;
    import org.codehaus.jackson.map.ObjectWriter;
    
    import javax.servlet.http.HttpServletResponse;
    
    import java.io.IOException;
    
    @Controller
    public class DemoController {
        private final ObjectMapper objectMapper = new ObjectMapper();
    
        @RequestMapping(value="/jsonOutput")
        @ResponseBody
        public String myObject(HttpServletResponse response) throws IOException {
            ObjectWriter objectWriter = objectMapper.writerWithView(Views.Public.class);
            return objectWriter.writeValueAsString(new MyObject());
        }
    
        public static class Views {
            static class Public {}
            static class ExtendPublic extends Public {}
        }
    
        public class MyObject {
            @JsonView(Views.Public.class) Integer id = 1;
            @JsonView(Views.ExtendPublic.class) String name = "name";
        }
    }
    

    Previous Edit: You need to instantiate the ObjectMapper and write out the object using a custom view as shown here, or in this example:

    Define views:

    class Views {
        static class Public {}
        static class ExtendedPublic extends PublicView {}
        ...
    }
    
    public class Thing {
        @JsonView(Views.Public.class) Integer id;
        @JsonView(Views.ExtendPublic.class) String name;
    }
    

    Use views:

    private final ObjectMapper objectMapper = new ObjectMapper();
    
    @RequestMapping(value = "/thing/{id}")
    public void getThing(@PathVariable final String id, HttpServletResponse response) {
        Thing thing = new Thing();
        objectMapper.writeValueUsingView(response.getWriter(), thing, Views.ExtendPublic.class);
    }
    

    If you are using Jackson >= 1.7 you might find that the @JSONFilter better suits your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I am using spring frameworking following is the mapping of url to controller <bean
I am using following class to show a grid like appearance with pagination on
I'm using JSF 2.0 with GlassFish 3.0. I have the following Managed Bean: @ManagedBean
I am using the following settings inside of Spring to create my mail sender.
With Spring I can autowire a bean with the following property: @PersistenceContext(unitName=foo) private EntityManager
I'm using spring based validation in combination with hibernate validator enabled by the following
I have a large application spread across multiple Spring bean definition xml files. In
I have question related to bean to json serialziation/deserialization using Jackson. Previously I have
I am using spring security core plug in in my grails app. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.