View Javadoc

1   /*
2    * $Id: MapperFactoryBean.java 19802 2010-09-30 21:33:26Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.json.config;
11  
12  import org.codehaus.jackson.map.ObjectMapper;
13  import org.springframework.beans.factory.config.AbstractFactoryBean;
14  
15  import java.util.Map;
16  
17  /**
18   * TODO
19   */
20  public class MapperFactoryBean extends AbstractFactoryBean<ObjectMapper>
21  {
22      private String name;
23      private Map<Class<?>, Class<?>> mixins;
24  
25      @Override
26      public Class<?> getObjectType()
27      {
28          return ObjectMapper.class;
29      }
30  
31      @Override
32      protected ObjectMapper createInstance() throws Exception
33      {
34          ObjectMapper mapper = new ObjectMapper();
35          if(mixins!=null)
36          {
37              for (Map.Entry<Class<?>, Class<?>> entry : mixins.entrySet())
38              {
39                  mapper.getSerializationConfig().addMixInAnnotations(entry.getKey(), entry.getValue());
40                  mapper.getDeserializationConfig().addMixInAnnotations(entry.getKey(), entry.getValue());
41              }
42          }
43          return mapper;
44      }
45  
46      public Map<Class<?>, Class<?>> getMixins()
47      {
48          return mixins;
49      }
50  
51      public void setMixins(Map<Class<?>, Class<?>> mixins)
52      {
53          this.mixins = mixins;
54      }
55  
56      public String getName()
57      {
58          return name;
59      }
60  
61      public void setName(String name)
62      {
63          this.name = name;
64      }
65  }