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