View Javadoc

1   /*
2    * $Id: JsonMapperResolver.java 20320 2010-11-24 15:03:31Z dfeist $
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.transformers;
11  
12  import org.mule.api.MuleContext;
13  import org.mule.config.transformer.AbstractAnnotatedTransformerArgumentResolver;
14  
15  import org.codehaus.jackson.map.ObjectMapper;
16  
17  /**
18   * This resolver is used by the transform engine to inject a {@link org.codehaus.jackson.map.ObjectMapper} into a method that requires it.
19   * A shared ObjectMapper context can be created for the application and stored in the registry, this will get injected
20   * into any transform methods that add {@link org.codehaus.jackson.map.ObjectMapper} to the method signature.
21   * <p/>
22   * If there is no shared Object Mapper one will be created for the transformer using the return type as the Json root element.
23   *
24   * @since 3.0
25   */
26  public class JsonMapperResolver extends AbstractAnnotatedTransformerArgumentResolver
27  {
28      public static final String ANNOTATIONS_PACKAGE_NAME = "org.codehaus.jackson";
29  
30      /**
31       * {@inheritDoc}
32       */
33      @Override
34      protected Class<?> getArgumentClass()
35      {
36          return ObjectMapper.class;
37      }
38  
39      /**
40       * {@inheritDoc}
41       */
42      @Override
43      protected Object createArgument(Class<?> annotatedType, MuleContext context) throws Exception
44      {
45          return new ObjectMapper();
46      }
47  
48      /**
49       * {@inheritDoc}
50       */
51      @Override
52      protected String getAnnotationsPackageName()
53      {
54          return ANNOTATIONS_PACKAGE_NAME;
55      }
56  }