title: JSon Serialization of a final class into Redis using Jackson ObjectMapper and spring-session
body: <p>I am about to use spring-session for writing the HttpSessions into Redis. I am basically putting maps into the session which should then be written into Redis.</p>
  
  <p>I am using the 
  <code>org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer</code> as Serializer which is setting up the Jackson ObjectMapper with:
  <code>mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);</code> but as the setting already states, it doesn't work with anything final (<a href="http://wiki.fasterxml.com/JacksonPolymorphicDeserialization" rel="nofollow">http://wiki.fasterxml.com/JacksonPolymorphicDeserialization</a>). </p>
  
  <p>I found out that somewhere in the CMS I am using (HippoCMS) the <code>FreemarkerServlet</code> is initialized including the following code:</p>
  
  <pre><code>void initializeSessionAndInstallModel(HttpServletRequest request,
              HttpServletResponse response, HttpSessionHashModel sessionModel, 
              HttpSession session)
              throws ServletException, IOException
      {
          session.setAttribute(ATTR_SESSION_MODEL, sessionModel);
          initializeSession(request, response);
      }
  </code></pre>
  
  <p>Unfortunately the <code>HttpSessionHashModel</code> is a final class and is written into the session. The serializer only writes sth. like <code>{"empty":true}</code> into Redis which makes it impossible for the Deserializer to deserialize the JSON cause no <code>@class</code> attribute is written into the JSon.</p>
  
  <p><strong>How can I tell the ObjectMapper to add a @class attribute for the final class. If it is not possible, what might be a possible solution for my problem?</strong></p>