Coverage Report - net.sf.json.JsonConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonConfig
0%
0/407
0%
0/186
1.688
 
 1  
 /*
 2  
  * Copyright 2002-2009 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package net.sf.json;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.Collections;
 22  
 import java.util.HashMap;
 23  
 import java.util.HashSet;
 24  
 import java.util.Iterator;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 import java.util.Set;
 28  
 
 29  
 import net.sf.json.processors.DefaultDefaultValueProcessor;
 30  
 import net.sf.json.processors.DefaultValueProcessor;
 31  
 import net.sf.json.processors.DefaultValueProcessorMatcher;
 32  
 import net.sf.json.processors.JsonBeanProcessor;
 33  
 import net.sf.json.processors.JsonBeanProcessorMatcher;
 34  
 import net.sf.json.processors.JsonValueProcessor;
 35  
 import net.sf.json.processors.JsonValueProcessorMatcher;
 36  
 import net.sf.json.processors.PropertyNameProcessor;
 37  
 import net.sf.json.processors.PropertyNameProcessorMatcher;
 38  
 import net.sf.json.util.CycleDetectionStrategy;
 39  
 import net.sf.json.util.JavaIdentifierTransformer;
 40  
 import net.sf.json.util.JsonEventListener;
 41  
 import net.sf.json.util.NewBeanInstanceStrategy;
 42  
 import net.sf.json.util.PropertyExclusionClassMatcher;
 43  
 import net.sf.json.util.PropertyFilter;
 44  
 import net.sf.json.util.PropertySetStrategy;
 45  
 
 46  
 import org.apache.commons.collections.map.MultiKeyMap;
 47  
 import org.apache.commons.lang.StringUtils;
 48  
 
 49  
 /**
 50  
  * Utility class that helps configuring the serialization process.
 51  
  * 
 52  
  * @author Andres Almiray <aalmiray@users.sourceforge.net>
 53  
  */
 54  
 public class JsonConfig {
 55  0
    public static final DefaultValueProcessorMatcher DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER = DefaultValueProcessorMatcher.DEFAULT;
 56  0
    public static final JsonBeanProcessorMatcher DEFAULT_JSON_BEAN_PROCESSOR_MATCHER = JsonBeanProcessorMatcher.DEFAULT;
 57  0
    public static final JsonValueProcessorMatcher DEFAULT_JSON_VALUE_PROCESSOR_MATCHER = JsonValueProcessorMatcher.DEFAULT;
 58  0
    public static final NewBeanInstanceStrategy DEFAULT_NEW_BEAN_INSTANCE_STRATEGY = NewBeanInstanceStrategy.DEFAULT;
 59  0
    public static final PropertyExclusionClassMatcher DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER = PropertyExclusionClassMatcher.DEFAULT;
 60  0
    public static final PropertyNameProcessorMatcher DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER = PropertyNameProcessorMatcher.DEFAULT;
 61  
    public static final int MODE_LIST = 1;
 62  
    public static final int MODE_OBJECT_ARRAY = 2;
 63  
    public static final int MODE_SET = 2;
 64  0
    private static final Class DEFAULT_COLLECTION_TYPE = List.class;
 65  0
    private static final CycleDetectionStrategy DEFAULT_CYCLE_DETECTION_STRATEGY = CycleDetectionStrategy.STRICT;
 66  0
    private static final String[] DEFAULT_EXCLUDES = new String[] { "class", "declaringClass", "metaClass" };
 67  0
    private static final JavaIdentifierTransformer DEFAULT_JAVA_IDENTIFIER_TRANSFORMER = JavaIdentifierTransformer.NOOP;
 68  0
    private static final DefaultValueProcessor DEFAULT_VALUE_PROCESSOR = new DefaultDefaultValueProcessor();
 69  0
    private static final String[] EMPTY_EXCLUDES = new String[0];
 70  
 
 71  
    /** Array conversion mode */
 72  0
    private int arrayMode = MODE_LIST;
 73  0
    private MultiKeyMap beanKeyMap = new MultiKeyMap();
 74  0
    private Map beanProcessorMap = new HashMap();
 75  0
    private MultiKeyMap beanTypeMap = new MultiKeyMap();
 76  
    /** Map of attribute/class */
 77  
    private Map classMap;
 78  0
    private Class collectionType = DEFAULT_COLLECTION_TYPE;
 79  0
    private CycleDetectionStrategy cycleDetectionStrategy = DEFAULT_CYCLE_DETECTION_STRATEGY;
 80  0
    private Map defaultValueMap = new HashMap();
 81  0
    private DefaultValueProcessorMatcher defaultValueProcessorMatcher = DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER;
 82  
    private Class enclosedType;
 83  0
    private List eventListeners = new ArrayList();
 84  0
    private String[] excludes = EMPTY_EXCLUDES;
 85  0
    private Map exclusionMap = new HashMap();
 86  
    private boolean handleJettisonEmptyElement;
 87  
    private boolean handleJettisonSingleElementArray;
 88  
    private boolean ignoreDefaultExcludes;
 89  
    //private boolean ignoreJPATransient;
 90  
    private boolean ignoreTransientFields;
 91  0
    private boolean ignorePublicFields = true;
 92  
    private boolean javascriptCompliant;
 93  0
    private JavaIdentifierTransformer javaIdentifierTransformer = DEFAULT_JAVA_IDENTIFIER_TRANSFORMER;
 94  
    private PropertyFilter javaPropertyFilter;
 95  0
    private Map javaPropertyNameProcessorMap = new HashMap();
 96  0
    private PropertyNameProcessorMatcher javaPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
 97  0
    private JsonBeanProcessorMatcher jsonBeanProcessorMatcher = DEFAULT_JSON_BEAN_PROCESSOR_MATCHER;
 98  
    private PropertyFilter jsonPropertyFilter;
 99  0
    private Map jsonPropertyNameProcessorMap = new HashMap();
 100  0
    private PropertyNameProcessorMatcher jsonPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
 101  0
    private JsonValueProcessorMatcher jsonValueProcessorMatcher = DEFAULT_JSON_VALUE_PROCESSOR_MATCHER;
 102  0
    private Map keyMap = new HashMap();
 103  0
    private NewBeanInstanceStrategy newBeanInstanceStrategy = DEFAULT_NEW_BEAN_INSTANCE_STRATEGY;
 104  0
    private PropertyExclusionClassMatcher propertyExclusionClassMatcher = DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER;
 105  
    private PropertySetStrategy propertySetStrategy;
 106  
    /** Root class used when converting to an specific bean */
 107  
    private Class rootClass;
 108  
    private boolean skipJavaIdentifierTransformationInMapKeys;
 109  
    private boolean triggerEvents;
 110  0
    private Map typeMap = new HashMap();
 111  0
    private List ignoreFieldAnnotations = new ArrayList();
 112  0
    private boolean allowNonStringKeys = false;
 113  
 
 114  0
    public JsonConfig() {
 115  0
    }
 116  
 
 117  
    /**
 118  
     * Registers a listener for JSON events.<br>
 119  
     * The events will be triggered only when using the static builders and if event triggering is
 120  
     * enabled.<br>
 121  
     * [Java -&gt; JSON]
 122  
     * 
 123  
     * @see #enableEventTriggering
 124  
     * @see #disableEventTriggering
 125  
     * @see #removeJsonEventListener(JsonEventListener)
 126  
     * @param listener a listener for events
 127  
     */
 128  
    public synchronized void addJsonEventListener( JsonEventListener listener ) {
 129  0
       if( !eventListeners.contains( listener ) ) {
 130  0
          eventListeners.add( listener );
 131  
       }
 132  0
    }
 133  
 
 134  
    /**
 135  
     * Removes all registered PropertyNameProcessors.<br>
 136  
     * [JSON -&gt; Java]
 137  
     */
 138  
    public void clearJavaPropertyNameProcessors() {
 139  0
       javaPropertyNameProcessorMap.clear();
 140  0
    }
 141  
 
 142  
    /**
 143  
     * Removes all registered JsonBeanProcessors.<br>
 144  
     * [Java -&gt; JSON]
 145  
     */
 146  
    public void clearJsonBeanProcessors() {
 147  0
       beanProcessorMap.clear();
 148  0
    }
 149  
 
 150  
    /**
 151  
     * Removes all registered listener for JSON Events.<br>
 152  
     * [Java -&gt; JSON]
 153  
     */
 154  
    public synchronized void clearJsonEventListeners() {
 155  0
       eventListeners.clear();
 156  0
    }
 157  
 
 158  
    /**
 159  
     * Removes all registered PropertyNameProcessors.<br>
 160  
     * [Java -&gt; JSON]
 161  
     */
 162  
    public void clearJsonPropertyNameProcessors() {
 163  0
       jsonPropertyNameProcessorMap.clear();
 164  0
    }   
 165  
    
 166  
    /**
 167  
     * Removes all registered JsonValueProcessors.<br>
 168  
     * [Java -&gt; JSON]
 169  
     */
 170  
    public void clearJsonValueProcessors() {
 171  0
       beanKeyMap.clear();
 172  0
       beanTypeMap.clear();
 173  0
       keyMap.clear();
 174  0
       typeMap.clear();
 175  0
    }
 176  
    
 177  
    /**
 178  
     * Removes all property exclusions registered per class.<br>
 179  
     * [Java -&gt; JSON]
 180  
     */
 181  
    public void clearPropertyExclusions() {
 182  0
       exclusionMap.clear();
 183  0
    }
 184  
 
 185  
    /**
 186  
     * Removes all registered PropertyNameProcessors.<br>
 187  
     * [JSON -&gt; Java]
 188  
     * 
 189  
     * @deprecated use clearJavaPropertyNameProcessors() instead
 190  
     */
 191  
    public void clearPropertyNameProcessors() {
 192  0
       clearJavaPropertyNameProcessors();
 193  0
    }
 194  
 
 195  
    public JsonConfig copy() {
 196  0
       JsonConfig jsc = new JsonConfig();
 197  0
       jsc.beanKeyMap.putAll( beanKeyMap );
 198  0
       jsc.beanTypeMap.putAll( beanTypeMap );
 199  0
       jsc.classMap = new HashMap();
 200  0
       if( classMap != null ) {
 201  0
          jsc.classMap.putAll( classMap );
 202  
       }
 203  0
       jsc.cycleDetectionStrategy = cycleDetectionStrategy;
 204  0
       if( eventListeners != null ) {
 205  0
          jsc.eventListeners.addAll( eventListeners );
 206  
       }
 207  0
       if( excludes != null ) {
 208  0
          jsc.excludes = new String[excludes.length];
 209  0
          System.arraycopy( excludes, 0, jsc.excludes, 0, excludes.length );
 210  
       }
 211  0
       jsc.handleJettisonEmptyElement = handleJettisonEmptyElement;
 212  0
       jsc.handleJettisonSingleElementArray = handleJettisonSingleElementArray;
 213  0
       jsc.ignoreDefaultExcludes = ignoreDefaultExcludes;
 214  0
       jsc.ignoreTransientFields = ignoreTransientFields;
 215  0
       jsc.ignorePublicFields = ignorePublicFields;
 216  0
       jsc.javaIdentifierTransformer = javaIdentifierTransformer;
 217  0
       jsc.javascriptCompliant = javascriptCompliant;
 218  0
       jsc.keyMap.putAll( keyMap );
 219  0
       jsc.beanProcessorMap.putAll( beanProcessorMap );
 220  0
       jsc.rootClass = rootClass;
 221  0
       jsc.skipJavaIdentifierTransformationInMapKeys = skipJavaIdentifierTransformationInMapKeys;
 222  0
       jsc.triggerEvents = triggerEvents;
 223  0
       jsc.typeMap.putAll( typeMap );
 224  0
       jsc.jsonPropertyFilter = jsonPropertyFilter;
 225  0
       jsc.javaPropertyFilter = javaPropertyFilter;
 226  0
       jsc.jsonBeanProcessorMatcher = jsonBeanProcessorMatcher;
 227  0
       jsc.newBeanInstanceStrategy = newBeanInstanceStrategy;
 228  0
       jsc.defaultValueProcessorMatcher = defaultValueProcessorMatcher;
 229  0
       jsc.defaultValueMap.putAll( defaultValueMap );
 230  0
       jsc.propertySetStrategy = propertySetStrategy;
 231  
       //jsc.ignoreJPATransient = ignoreJPATransient;
 232  0
       jsc.collectionType = collectionType;
 233  0
       jsc.enclosedType = enclosedType;
 234  0
       jsc.jsonValueProcessorMatcher = jsonValueProcessorMatcher;
 235  0
       jsc.javaPropertyNameProcessorMatcher = javaPropertyNameProcessorMatcher;
 236  0
       jsc.javaPropertyNameProcessorMap.putAll( javaPropertyNameProcessorMap );
 237  0
       jsc.jsonPropertyNameProcessorMatcher = jsonPropertyNameProcessorMatcher;
 238  0
       jsc.jsonPropertyNameProcessorMap.putAll( jsonPropertyNameProcessorMap );
 239  0
       jsc.propertyExclusionClassMatcher = propertyExclusionClassMatcher;
 240  0
       jsc.exclusionMap.putAll(  exclusionMap );
 241  0
       jsc.ignoreFieldAnnotations.addAll( ignoreFieldAnnotations );
 242  0
       jsc.allowNonStringKeys = allowNonStringKeys;
 243  0
       return jsc;
 244  
    }
 245  
 
 246  
    /**
 247  
     * Disables event triggering when building.<br>
 248  
     * [Java -&gt; JSON]
 249  
     */
 250  
    public void disableEventTriggering() {
 251  0
       triggerEvents = false;
 252  0
    }
 253  
 
 254  
    /**
 255  
     * Enables event triggering when building.<br>
 256  
     * [Java -&gt; JSON]
 257  
     */
 258  
    public void enableEventTriggering() {
 259  0
       triggerEvents = true;
 260  0
    }
 261  
 
 262  
    /**
 263  
     * Finds a DefaultValueProcessor registered to the target class.<br>
 264  
     * Returns null if none is registered.<br>
 265  
     * [Java -&gt; JSON]
 266  
     * 
 267  
     * @param target a class used for searching a DefaultValueProcessor.
 268  
     */
 269  
    public DefaultValueProcessor findDefaultValueProcessor( Class target ) {
 270  0
       if( !defaultValueMap.isEmpty() ) {
 271  0
          Object key = defaultValueProcessorMatcher.getMatch( target, defaultValueMap.keySet() );
 272  0
          DefaultValueProcessor processor = (DefaultValueProcessor) defaultValueMap.get( key );
 273  0
          if( processor != null ) {
 274  0
             return processor;
 275  
          }
 276  
       }
 277  0
       return DEFAULT_VALUE_PROCESSOR;
 278  
    }
 279  
 
 280  
    /**
 281  
     * Finds a PropertyNameProcessor registered to the target class.<br>
 282  
     * Returns null if none is registered.<br>
 283  
     * [JSON -&gt; Java]
 284  
     * 
 285  
     * @param propertyType a class used for searching a PropertyNameProcessor.
 286  
     */
 287  
    public PropertyNameProcessor findJavaPropertyNameProcessor( Class beanClass ) {
 288  0
       if( !javaPropertyNameProcessorMap.isEmpty() ) {
 289  0
          Object key = javaPropertyNameProcessorMatcher.getMatch( beanClass, javaPropertyNameProcessorMap.keySet() );
 290  0
          return (PropertyNameProcessor) javaPropertyNameProcessorMap.get( key );
 291  
 
 292  
       }
 293  0
       return null;
 294  
    }
 295  
 
 296  
    /**
 297  
     * Finds a JsonBeanProcessor registered to the target class.<br>
 298  
     * Returns null if none is registered.<br>
 299  
     * [Java -&gt; JSON]
 300  
     * 
 301  
     * @param target a class used for searching a JsonBeanProcessor.
 302  
     */
 303  
    public JsonBeanProcessor findJsonBeanProcessor( Class target ) {
 304  0
       if( !beanProcessorMap.isEmpty() ) {
 305  0
          Object key = jsonBeanProcessorMatcher.getMatch( target, beanProcessorMap.keySet() );
 306  0
          return (JsonBeanProcessor) beanProcessorMap.get( key );
 307  
       }
 308  0
       return null;
 309  
    }
 310  
 
 311  
    /**
 312  
     * Finds a PropertyNameProcessor registered to the target class.<br>
 313  
     * Returns null if none is registered.<br>
 314  
     * [Java -&gt; JSON]
 315  
     * 
 316  
     * @param propertyType a class used for searching a PropertyNameProcessor.
 317  
     */
 318  
    public PropertyNameProcessor findJsonPropertyNameProcessor( Class beanClass ) {
 319  0
       if( !jsonPropertyNameProcessorMap.isEmpty() ) {
 320  0
          Object key = jsonPropertyNameProcessorMatcher.getMatch( beanClass, jsonPropertyNameProcessorMap.keySet() );
 321  0
          return (PropertyNameProcessor) jsonPropertyNameProcessorMap.get( key );
 322  
 
 323  
       }
 324  0
       return null;
 325  
    }
 326  
 
 327  
    /**
 328  
     * Finds a JsonValueProcessor registered to the target type.<br>
 329  
     * Returns null if none is registered.<br>
 330  
     * [Java -&gt; JSON]
 331  
     * 
 332  
     * @param propertyType a class used for searching a JsonValueProcessor.
 333  
     */
 334  
    public JsonValueProcessor findJsonValueProcessor( Class propertyType ) {
 335  0
       if( !typeMap.isEmpty() ) {
 336  0
          Object key = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
 337  0
          return (JsonValueProcessor) typeMap.get( key );
 338  
 
 339  
       }
 340  0
       return null;
 341  
    }
 342  
 
 343  
    /**
 344  
     * Finds a JsonValueProcessor.<br>
 345  
     * It will search the registered JsonValueProcessors in the following order:
 346  
     * <ol>
 347  
     * <li>beanClass, key</li>
 348  
     * <li>beanClass, type</li>
 349  
     * <li>key</li>
 350  
     * <li>type</li>
 351  
     * </ol>
 352  
     * Returns null if none is registered.<br>
 353  
     * [Java -&gt; JSON]
 354  
     * 
 355  
     * @param beanClass the class to which the property may belong
 356  
     * @param propertyType the type of the property
 357  
     * @param key the name of the property which may belong to the target class
 358  
     */
 359  
    public JsonValueProcessor findJsonValueProcessor( Class beanClass, Class propertyType, String key ) {
 360  0
       JsonValueProcessor jsonValueProcessor = null;
 361  0
       jsonValueProcessor = (JsonValueProcessor) beanKeyMap.get( beanClass, key );
 362  0
       if( jsonValueProcessor != null ) {
 363  0
          return jsonValueProcessor;
 364  
       }
 365  
 
 366  0
       jsonValueProcessor = (JsonValueProcessor) beanTypeMap.get( beanClass, propertyType );
 367  0
       if( jsonValueProcessor != null ) {
 368  0
          return jsonValueProcessor;
 369  
       }
 370  
 
 371  0
       jsonValueProcessor = (JsonValueProcessor) keyMap.get( key );
 372  0
       if( jsonValueProcessor != null ) {
 373  0
          return jsonValueProcessor;
 374  
       }
 375  
 
 376  0
       Object tkey = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
 377  0
       jsonValueProcessor = (JsonValueProcessor) typeMap.get( tkey );
 378  0
       if( jsonValueProcessor != null ) {
 379  0
          return jsonValueProcessor;
 380  
       }
 381  
 
 382  0
       return null;
 383  
    }
 384  
 
 385  
    /**
 386  
     * Finds a JsonValueProcessor.<br>
 387  
     * It will search the registered JsonValueProcessors in the following order:
 388  
     * <ol>
 389  
     * <li>key</li>
 390  
     * <li>type</li>
 391  
     * </ol>
 392  
     * Returns null if none is registered.<br>
 393  
     * [Java -&gt; JSON]
 394  
     * 
 395  
     * @param propertyType the type of the property
 396  
     * @param key the name of the property which may belong to the target class
 397  
     */
 398  
    public JsonValueProcessor findJsonValueProcessor( Class propertyType, String key ) {
 399  0
       JsonValueProcessor jsonValueProcessor = null;
 400  0
       jsonValueProcessor = (JsonValueProcessor) keyMap.get( key );
 401  0
       if( jsonValueProcessor != null ) {
 402  0
          return jsonValueProcessor;
 403  
       }
 404  
 
 405  0
       Object tkey = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
 406  0
       jsonValueProcessor = (JsonValueProcessor) typeMap.get( tkey );
 407  0
       if( jsonValueProcessor != null ) {
 408  0
          return jsonValueProcessor;
 409  
       }
 410  
 
 411  0
       return null;
 412  
    }
 413  
    
 414  
    /**
 415  
     * Finds a PropertyNameProcessor registered to the target class.<br>
 416  
     * Returns null if none is registered. <br>
 417  
     * [JSON -&gt; Java]
 418  
     * 
 419  
     * @param propertyType a class used for searching a PropertyNameProcessor.
 420  
     * 
 421  
     * @deprecated use findJavaPropertyNameProcessor() instead
 422  
     */
 423  
    public PropertyNameProcessor findPropertyNameProcessor( Class beanClass ) {
 424  0
       return findJavaPropertyNameProcessor( beanClass );
 425  
    }   
 426  
    
 427  
    /**
 428  
     * Returns the current array mode conversion.<br>
 429  
     * [JSON -&gt; Java]
 430  
     * 
 431  
     * @return MODE_OBJECT_ARRAY, MODE_LIST or MODE_SET
 432  
     */
 433  
    public int getArrayMode() {
 434  0
       return arrayMode;
 435  
    }
 436  
 
 437  
    /**
 438  
     * Returns the current attribute/class Map.<br>
 439  
     * [JSON -&gt; Java]
 440  
     * 
 441  
     * @return a Map of classes, every key identifies a property or a regexp
 442  
     */
 443  
    public Map getClassMap() {
 444  0
       return classMap;
 445  
    }
 446  
 
 447  
    /**
 448  
     * Returns the current collection type used for collection transformations.<br>
 449  
     * [JSON -&gt; Java]
 450  
     * 
 451  
     * @return the target collection class for conversion
 452  
     */
 453  
    public Class getCollectionType() {
 454  0
       return collectionType;
 455  
    }
 456  
 
 457  
    /**
 458  
     * Returns the configured CycleDetectionStrategy.<br>
 459  
     * Default value is CycleDetectionStrategy.STRICT<br>
 460  
     * [Java -&gt; JSON]
 461  
     */
 462  
    public CycleDetectionStrategy getCycleDetectionStrategy() {
 463  0
       return cycleDetectionStrategy;
 464  
    }
 465  
 
 466  
    /**
 467  
     * Returns the configured DefaultValueProcessorMatcher.<br>
 468  
     * Default value is DefaultValueProcessorMatcher.DEFAULT<br>
 469  
     * [Java -&gt; JSON]
 470  
     */
 471  
    public DefaultValueProcessorMatcher getDefaultValueProcessorMatcher() {
 472  0
       return defaultValueProcessorMatcher;
 473  
    }
 474  
 
 475  
    /**
 476  
     * Returns the current enclosed type for generic collection transformations.<br>
 477  
     * [JSON -&gt; Java]
 478  
     * 
 479  
     * @return the target type for conversion
 480  
     */
 481  
    public Class getEnclosedType() {
 482  0
       return enclosedType;
 483  
    }
 484  
 
 485  
    /**
 486  
     * Returns the configured properties for exclusion. <br>
 487  
     * [Java -&gt; JSON]
 488  
     */
 489  
    public String[] getExcludes() {
 490  0
       return excludes;
 491  
    }
 492  
 
 493  
    /**
 494  
     * Returns the configured JavaIdentifierTransformer. <br>
 495  
     * Default value is JavaIdentifierTransformer.NOOP<br>
 496  
     * [JSON -&gt; Java]
 497  
     */
 498  
    public JavaIdentifierTransformer getJavaIdentifierTransformer() {
 499  0
       return javaIdentifierTransformer;
 500  
    }
 501  
 
 502  
    /**
 503  
     * Returns the configured property filter when serializing to Java.<br>
 504  
     * [JSON -&gt; Java]
 505  
     */
 506  
    public PropertyFilter getJavaPropertyFilter() {
 507  0
       return javaPropertyFilter;
 508  
    }
 509  
 
 510  
    /**
 511  
     * Returns the configured PropertyNameProcessorMatcher.<br>
 512  
     * Default value is PropertyNameProcessorMatcher.DEFAULT<br>
 513  
     * [JSON -&gt; Java]
 514  
     */
 515  
    public PropertyNameProcessorMatcher getJavaPropertyNameProcessorMatcher() {
 516  0
       return javaPropertyNameProcessorMatcher;
 517  
    }
 518  
    
 519  
    /**
 520  
     * Returns the configured JsonBeanProcessorMatcher.<br>
 521  
     * Default value is JsonBeanProcessorMatcher.DEFAULT<br>
 522  
     * [JSON -&gt; Java]
 523  
     */
 524  
    public JsonBeanProcessorMatcher getJsonBeanProcessorMatcher() {
 525  0
       return jsonBeanProcessorMatcher;
 526  
    }
 527  
 
 528  
    /**
 529  
     * Returns a list of registered listeners for JSON events.<br>
 530  
     * [JSON -&gt; Java]
 531  
     */
 532  
    public synchronized List getJsonEventListeners() {
 533  0
       return eventListeners;
 534  
    }
 535  
 
 536  
    /**
 537  
     * Returns the configured property filter when serializing to JSON.<br>
 538  
     * [Java -&gt; JSON]
 539  
     */
 540  
    public PropertyFilter getJsonPropertyFilter() {
 541  0
       return jsonPropertyFilter;
 542  
    }
 543  
 
 544  
    /**
 545  
     * Returns the configured PropertyNameProcessorMatcher.<br>
 546  
     * Default value is PropertyNameProcessorMatcher.DEFAULT<br>
 547  
     * [Java -&gt; JSON]
 548  
     */
 549  
    public PropertyNameProcessorMatcher getJsonPropertyNameProcessorMatcher() {
 550  0
       return javaPropertyNameProcessorMatcher;
 551  
    }
 552  
 
 553  
    /**
 554  
     * Returns the configured JsonValueProcessorMatcher.<br>
 555  
     * Default value is JsonValueProcessorMatcher.DEFAULT<br>
 556  
     * [Java -&gt; JSON]
 557  
     */
 558  
    public JsonValueProcessorMatcher getJsonValueProcessorMatcher() {
 559  0
       return jsonValueProcessorMatcher;
 560  
    }
 561  
 
 562  
    /**
 563  
     * Returns a set of default excludes with user-defined excludes.<br>
 564  
     * [Java -&gt; JSON]
 565  
     */
 566  
    public Collection getMergedExcludes() {
 567  0
       Collection exclusions = new HashSet();
 568  0
       for( int i = 0; i < excludes.length; i++ ) {
 569  0
          String exclusion = excludes[i];
 570  0
          if( !StringUtils.isBlank( excludes[i] ) ) {
 571  0
             exclusions.add( exclusion.trim() );
 572  
          }
 573  
       }
 574  
 
 575  0
       if( !ignoreDefaultExcludes ) {
 576  0
          for( int i = 0; i < DEFAULT_EXCLUDES.length; i++ ) {
 577  0
             if( !exclusions.contains( DEFAULT_EXCLUDES[i] ) ) {
 578  0
                exclusions.add( DEFAULT_EXCLUDES[i] );
 579  
             }
 580  
          }
 581  
       }
 582  
 
 583  0
       return exclusions;
 584  
    }
 585  
    
 586  
    /**
 587  
     * Returns a set of default excludes with user-defined excludes.<br>
 588  
     * Takes into account any additional excludes per matching class.
 589  
     * [Java -&gt; JSON]
 590  
     */
 591  
    public Collection getMergedExcludes( Class target ) {
 592  0
       if( target == null ) {
 593  0
          return getMergedExcludes();
 594  
       }
 595  
 
 596  0
       Collection exclusionSet = getMergedExcludes();
 597  0
       if( !exclusionMap.isEmpty() ) {
 598  0
          Object key = propertyExclusionClassMatcher.getMatch( target, exclusionMap.keySet() );
 599  0
          Set set = (Set) exclusionMap.get( key );
 600  0
          if( set != null && !set.isEmpty() ) {
 601  0
             for( Iterator i = set.iterator(); i.hasNext(); ) {
 602  0
                Object e = i.next();
 603  0
                if( !exclusionSet.contains( e ) ) {
 604  0
                   exclusionSet.add( e );
 605  
                }
 606  0
             }
 607  
          }
 608  
       }
 609  
 
 610  0
       return exclusionSet;
 611  
    }
 612  
 
 613  
    /**
 614  
     * Returns the configured NewBeanInstanceStrategy.<br>
 615  
     * Default value is NewBeanInstanceStrategy.DEFAULT<br>
 616  
     * [JSON -&gt; Java]
 617  
     */
 618  
    public NewBeanInstanceStrategy getNewBeanInstanceStrategy() {
 619  0
       return newBeanInstanceStrategy;
 620  
    }
 621  
    
 622  
    /**
 623  
     * Returns the configured PropertyExclusionClassMatcher.<br>
 624  
     * Default value is PropertyExclusionClassMatcher.DEFAULT<br>
 625  
     * [JSON -&gt; Java]
 626  
     */
 627  
    public PropertyExclusionClassMatcher getPropertyExclusionClassMatcher() {
 628  0
       return propertyExclusionClassMatcher;
 629  
    }
 630  
    
 631  
    /**
 632  
     * Returns the configured PropertyNameProcessorMatcher.<br>
 633  
     * Default value is PropertyNameProcessorMatcher.DEFAULT<br>
 634  
     * [JSON -&gt; Java]
 635  
     * 
 636  
     * @deprecated use getJavaPropertyNameProcessorMatcher() instead
 637  
     */
 638  
    public PropertyNameProcessorMatcher getPropertyNameProcessorMatcher() {
 639  0
       return getJavaPropertyNameProcessorMatcher();
 640  
    }
 641  
 
 642  
    /**
 643  
     * Returns the configured PropertySetStrategy.<br>
 644  
     * Default value is PropertySetStrategy.DEFAULT<br>
 645  
     * [JSON -&gt; Java]
 646  
     */
 647  
    public PropertySetStrategy getPropertySetStrategy() {
 648  0
       return propertySetStrategy;
 649  
    }
 650  
 
 651  
    /**
 652  
     * Returns the current root Class.<br>
 653  
     * [JSON -&gt; Java]
 654  
     * 
 655  
     * @return the target class for conversion
 656  
     */
 657  
    public Class getRootClass() {
 658  0
       return rootClass;
 659  
    }
 660  
 
 661  
    /**
 662  
     * Returns true if non-String keys are allowed on JSONObject.<br>
 663  
     * Default value is false<br>
 664  
     * [Java -&gt; JSON]
 665  
     */
 666  
    public boolean isAllowNonStringKeys() {
 667  0
       return allowNonStringKeys;
 668  
    }
 669  
    
 670  
    /**
 671  
     * Returns true if event triggering is enabled during building.<br>
 672  
     * Default value is false<br>
 673  
     * [Java -&gt; JSON]
 674  
     */
 675  
    public boolean isEventTriggeringEnabled() {
 676  0
       return triggerEvents;
 677  
    }
 678  
 
 679  
    /**
 680  
     * Returns true if this Jettison convention will be handled when converting to Java.<br>
 681  
     * Jettison assumes that "" (empty string) can be assigned to empty elements (objects), which
 682  
     * clearly violates the JSON spec.<br>
 683  
     * [JSON -&gt; Java]
 684  
     */
 685  
    public boolean isHandleJettisonEmptyElement() {
 686  0
       return handleJettisonEmptyElement;
 687  
    }
 688  
 
 689  
    /**
 690  
     * Returns true if this jettison convention will be handled when converting to Java.<br>
 691  
     * Jettison states the following JSON {'media':{'title':'hello'}} can be set as a single element
 692  
     * JSONArray (media is the array).<br>
 693  
     * [JSON -&gt; Java]
 694  
     */
 695  
    public boolean isHandleJettisonSingleElementArray() {
 696  0
       return handleJettisonSingleElementArray;
 697  
    }
 698  
 
 699  
    /**
 700  
     * Returns true if default excludes will not be used.<br>
 701  
     * Default value is false.<br>
 702  
     * [Java -&gt; JSON]
 703  
     */
 704  
    public boolean isIgnoreDefaultExcludes() {
 705  0
       return ignoreDefaultExcludes;
 706  
    }
 707  
 
 708  
    /**
 709  
     * Returns true if JPA Transient annotated methods should be ignored.<br>
 710  
     * Default value is false.<br>
 711  
     * [Java -&gt; JSON]
 712  
     */
 713  
    public boolean isIgnoreJPATransient() {
 714  0
       return ignoreFieldAnnotations.contains("javax.persistence.Transient");
 715  
    }
 716  
 
 717  
    /**
 718  
     * Returns true if transient fields of a bean will be ignored.<br>
 719  
     * Default value is false.<br>
 720  
     * [Java -&gt; JSON]
 721  
     */
 722  
    public boolean isIgnoreTransientFields() {
 723  0
       return ignoreTransientFields;
 724  
    }
 725  
    
 726  
    /**
 727  
     * Returns true if public fields of a bean will be ignored.<br>
 728  
     * Default value is true.<br>
 729  
     * [Java -&gt; JSON]
 730  
     */
 731  
    public boolean isIgnorePublicFields() {
 732  0
       return ignorePublicFields;
 733  
    }
 734  
    
 735  
    /**
 736  
     * Returns true if Javascript compatibility is turned on.<br>
 737  
     * Default value is false.<br>
 738  
     * [Java -&gt; JSON]
 739  
     */
 740  
    public boolean isJavascriptCompliant() {
 741  0
       return javascriptCompliant;
 742  
    }
 743  
 
 744  
    /**
 745  
     * Returns true if map keys will not be transformed.<br>
 746  
     * Default value is false.<br>
 747  
     * [JSON -&gt; Java]
 748  
     */
 749  
    public boolean isSkipJavaIdentifierTransformationInMapKeys() {
 750  0
       return skipJavaIdentifierTransformationInMapKeys;
 751  
    }
 752  
 
 753  
    /**
 754  
     * Registers a DefaultValueProcessor.<br>
 755  
     * [Java -&gt; JSON]
 756  
     * 
 757  
     * @param target the class to use as key
 758  
     * @param defaultValueProcessor the processor to register
 759  
     */
 760  
    public void registerDefaultValueProcessor( Class target, DefaultValueProcessor defaultValueProcessor ) {
 761  0
       if( target != null && defaultValueProcessor != null ) {
 762  0
          defaultValueMap.put( target, defaultValueProcessor );
 763  
       }
 764  0
    }
 765  
 
 766  
    /**
 767  
     * Registers a PropertyNameProcessor.<br>
 768  
     * [JSON -&gt; Java]
 769  
     * 
 770  
     * @param target the class to use as key
 771  
     * @param propertyNameProcessor the processor to register
 772  
     */
 773  
    public void registerJavaPropertyNameProcessor( Class target, PropertyNameProcessor propertyNameProcessor ) {
 774  0
       if( target != null && propertyNameProcessor != null ) {
 775  0
          javaPropertyNameProcessorMap.put( target, propertyNameProcessor );
 776  
       }
 777  0
    }
 778  
    
 779  
    /**
 780  
     * Registers a JsonBeanProcessor.<br>
 781  
     * [Java -&gt; JSON]
 782  
     * 
 783  
     * @param target the class to use as key
 784  
     * @param jsonBeanProcessor the processor to register
 785  
     */
 786  
    public void registerJsonBeanProcessor( Class target, JsonBeanProcessor jsonBeanProcessor ) {
 787  0
       if( target != null && jsonBeanProcessor != null ) {
 788  0
          beanProcessorMap.put( target, jsonBeanProcessor );
 789  
       }
 790  0
    }
 791  
 
 792  
    /**
 793  
     * Registers a PropertyNameProcessor.<br>
 794  
     * [Java -&gt; JSON]
 795  
     * 
 796  
     * @param target the class to use as key
 797  
     * @param propertyNameProcessor the processor to register
 798  
     */
 799  
    public void registerJsonPropertyNameProcessor( Class target, PropertyNameProcessor propertyNameProcessor ) {
 800  0
       if( target != null && propertyNameProcessor != null ) {
 801  0
          jsonPropertyNameProcessorMap.put( target, propertyNameProcessor );
 802  
       }
 803  0
    }
 804  
 
 805  
    /**
 806  
     * Registers a JsonValueProcessor.<br>
 807  
     * [Java -&gt; JSON]
 808  
     * 
 809  
     * @param beanClass the class to use as key
 810  
     * @param propertyType the property type to use as key
 811  
     * @param jsonValueProcessor the processor to register
 812  
     */
 813  
    public void registerJsonValueProcessor( Class beanClass, Class propertyType, JsonValueProcessor jsonValueProcessor ) {
 814  0
       if( beanClass != null && propertyType != null && jsonValueProcessor != null ) {
 815  0
          beanTypeMap.put( beanClass, propertyType, jsonValueProcessor );
 816  
       }
 817  0
    }
 818  
 
 819  
    /**
 820  
     * Registers a JsonValueProcessor.<br>
 821  
     * [Java -&gt; JSON]
 822  
     * 
 823  
     * @param propertyType the property type to use as key
 824  
     * @param jsonValueProcessor the processor to register
 825  
     */
 826  
    public void registerJsonValueProcessor( Class propertyType, JsonValueProcessor jsonValueProcessor ) {
 827  0
       if( propertyType != null && jsonValueProcessor != null ) {
 828  0
          typeMap.put( propertyType, jsonValueProcessor );
 829  
       }
 830  0
    }
 831  
 
 832  
    /**
 833  
     * Registers a JsonValueProcessor.<br>
 834  
     * [Java -&gt; JSON]
 835  
     * 
 836  
     * @param beanClass the class to use as key
 837  
     * @param key the property name to use as key
 838  
     * @param jsonValueProcessor the processor to register
 839  
     */
 840  
    public void registerJsonValueProcessor( Class beanClass, String key, JsonValueProcessor jsonValueProcessor ) {
 841  0
       if( beanClass != null && key != null && jsonValueProcessor != null ) {
 842  0
          beanKeyMap.put( beanClass, key, jsonValueProcessor );
 843  
       }
 844  0
    }
 845  
 
 846  
    /**
 847  
     * Registers a JsonValueProcessor.<br>
 848  
     * [Java -&gt; JSON]
 849  
     * 
 850  
     * @param key the property name to use as key
 851  
     * @param jsonValueProcessor the processor to register
 852  
     */
 853  
    public void registerJsonValueProcessor( String key, JsonValueProcessor jsonValueProcessor ) {
 854  0
       if( key != null && jsonValueProcessor != null ) {
 855  0
          keyMap.put( key, jsonValueProcessor );
 856  
       }
 857  0
    }
 858  
    
 859  
    /**
 860  
     * Registers a exclusion for a target class.<br>
 861  
     * [Java -&gt; JSON]
 862  
     * 
 863  
     * @param target the class to use as key
 864  
     * @param propertyName the property to be excluded
 865  
     */
 866  
    public void registerPropertyExclusion( Class target, String propertyName ) {
 867  0
       if( target != null && propertyName != null ) {
 868  0
          Set set = (Set) exclusionMap.get( target );
 869  0
          if( set == null ){
 870  0
             set = new HashSet();
 871  0
             exclusionMap.put(  target, set );
 872  
          }
 873  0
          if( !set.contains( propertyName )){
 874  0
             set.add(propertyName );
 875  
          }
 876  
       }
 877  0
    }
 878  
    
 879  
    /**
 880  
     * Registers exclusions for a target class.<br>
 881  
     * [Java -&gt; JSON]
 882  
     * 
 883  
     * @param target the class to use as key
 884  
     * @param properties the properties to be excluded
 885  
     */
 886  
    public void registerPropertyExclusions( Class target, String[] properties ) {
 887  0
       if( target != null && properties != null && properties.length > 0 ) {
 888  0
          Set set = (Set) exclusionMap.get( target );
 889  0
          if( set == null ) {
 890  0
             set = new HashSet();
 891  0
             exclusionMap.put( target, set );
 892  
          }
 893  0
          for( int i = 0; i < properties.length; i++ ) {
 894  0
             if( !set.contains( properties[i] ) ) {
 895  0
                set.add( properties[i] );
 896  
             }
 897  
          }
 898  
       }
 899  0
    }
 900  
    
 901  
    /**
 902  
     * Registers a PropertyNameProcessor.<br>
 903  
     * [JSON -&gt; Java]
 904  
     * 
 905  
     * @param target the class to use as key
 906  
     * @param propertyNameProcessor the processor to register
 907  
     * 
 908  
     * @deprecated use registerJavaPropertyNameProcessor() instead
 909  
     */
 910  
    public void registerPropertyNameProcessor( Class target, PropertyNameProcessor propertyNameProcessor ) {
 911  0
       registerJavaPropertyNameProcessor( target, propertyNameProcessor );
 912  0
    }
 913  
 
 914  
    /**
 915  
     * Removes a listener for JSON events.<br>
 916  
     * [Java -&gt; JSON]
 917  
     * 
 918  
     * @see #addJsonEventListener(JsonEventListener)
 919  
     * @param listener a listener for events
 920  
     */
 921  
    public synchronized void removeJsonEventListener( JsonEventListener listener ) {
 922  0
       eventListeners.remove( listener );
 923  0
    }
 924  
 
 925  
    /**
 926  
     * Resets all values to its default state.
 927  
     */
 928  
    public void reset() {
 929  0
       excludes = EMPTY_EXCLUDES;
 930  0
       ignoreDefaultExcludes = false;
 931  0
       ignoreTransientFields = false;
 932  0
       ignorePublicFields = true;
 933  0
       javascriptCompliant = false;
 934  0
       javaIdentifierTransformer = DEFAULT_JAVA_IDENTIFIER_TRANSFORMER;
 935  0
       cycleDetectionStrategy = DEFAULT_CYCLE_DETECTION_STRATEGY;
 936  0
       skipJavaIdentifierTransformationInMapKeys = false;
 937  0
       triggerEvents = false;
 938  0
       handleJettisonEmptyElement = false;
 939  0
       handleJettisonSingleElementArray = false;
 940  0
       arrayMode = MODE_LIST;
 941  0
       rootClass = null;
 942  0
       classMap = null;
 943  0
       keyMap.clear();
 944  0
       typeMap.clear();
 945  0
       beanKeyMap.clear();
 946  0
       beanTypeMap.clear();
 947  0
       jsonPropertyFilter = null;
 948  0
       javaPropertyFilter = null;
 949  0
       jsonBeanProcessorMatcher = DEFAULT_JSON_BEAN_PROCESSOR_MATCHER;
 950  0
       newBeanInstanceStrategy = DEFAULT_NEW_BEAN_INSTANCE_STRATEGY;
 951  0
       defaultValueProcessorMatcher = DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER;
 952  0
       defaultValueMap.clear();
 953  0
       propertySetStrategy = null/* DEFAULT_PROPERTY_SET_STRATEGY */;
 954  
       //ignoreJPATransient = false;
 955  0
       collectionType = DEFAULT_COLLECTION_TYPE;
 956  0
       enclosedType = null;
 957  0
       jsonValueProcessorMatcher = DEFAULT_JSON_VALUE_PROCESSOR_MATCHER;
 958  0
       javaPropertyNameProcessorMap.clear();
 959  0
       javaPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
 960  0
       jsonPropertyNameProcessorMap.clear();
 961  0
       jsonPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
 962  0
       beanProcessorMap.clear();
 963  0
       propertyExclusionClassMatcher = DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER;
 964  0
       exclusionMap.clear();
 965  0
       ignoreFieldAnnotations.clear();
 966  0
       allowNonStringKeys = false;
 967  0
    }
 968  
 
 969  
    /**
 970  
     * Sets if non-String keys are allowed on JSONObject.<br>
 971  
     * [Java -&gt; JSON]
 972  
     */
 973  
    public void setAllowNonStringKeys( boolean allowNonStringKeys ) {
 974  0
       this.allowNonStringKeys = allowNonStringKeys;
 975  0
    }
 976  
    
 977  
    /**
 978  
     * Sets the current array mode for conversion.<br>
 979  
     * If the value is not MODE_LIST, MODE_OBJECT_ARRAY nor MODE_SET, then MODE_LIST will be used.<br>
 980  
     * [JSON -&gt; Java]
 981  
     * 
 982  
     * @param arrayMode array mode for conversion
 983  
     */
 984  
    public void setArrayMode( int arrayMode ) {
 985  0
       if( arrayMode == MODE_OBJECT_ARRAY ) {
 986  0
          this.arrayMode = arrayMode;
 987  0
       } else if( arrayMode == MODE_SET ) {
 988  0
          this.arrayMode = arrayMode;
 989  0
          this.collectionType = Set.class;
 990  
       } else {
 991  0
          this.arrayMode = MODE_LIST;
 992  0
          this.enclosedType = DEFAULT_COLLECTION_TYPE;
 993  
       }
 994  0
    }
 995  
 
 996  
    /**
 997  
     * Sets the current attribute/Class Map<br>
 998  
     * [JSON -&gt; Java]
 999  
     * 
 1000  
     * @param classMap a Map of classes, every key identifies a property or a regexp
 1001  
     */
 1002  
    public void setClassMap( Map classMap ) {
 1003  0
       this.classMap = classMap;
 1004  0
    }
 1005  
 
 1006  
    /**
 1007  
     * Sets the current collection type used for collection transformations.<br>
 1008  
     * [JSON -&gt; Java]
 1009  
     * 
 1010  
     * @param collectionType the target collection class for conversion
 1011  
     */
 1012  
    public void setCollectionType( Class collectionType ) {
 1013  0
       if( collectionType != null ) {
 1014  0
          if( !Collection.class.isAssignableFrom( collectionType ) ) {
 1015  0
             throw new JSONException( "The configured collectionType is not a Collection: " + collectionType.getName() );
 1016  
          }
 1017  0
          this.collectionType = collectionType;
 1018  
       } else {
 1019  0
          collectionType = DEFAULT_COLLECTION_TYPE;
 1020  
       }
 1021  0
    }
 1022  
 
 1023  
    /**
 1024  
     * Sets a CycleDetectionStrategy to use.<br>
 1025  
     * Will set default value (CycleDetectionStrategy.STRICT) if null.<br>
 1026  
     * [Java -&gt; JSON]
 1027  
     */
 1028  
    public void setCycleDetectionStrategy( CycleDetectionStrategy cycleDetectionStrategy ) {
 1029  0
       this.cycleDetectionStrategy = cycleDetectionStrategy == null ? DEFAULT_CYCLE_DETECTION_STRATEGY
 1030  
             : cycleDetectionStrategy;
 1031  0
    }
 1032  
 
 1033  
    /**
 1034  
     * Sets a DefaultValueProcessorMatcher to use.<br>
 1035  
     * Will set default value (DefaultValueProcessorMatcher.DEFAULT) if null.<br>
 1036  
     * [Java -&gt; JSON]
 1037  
     */
 1038  
    public void setDefaultValueProcessorMatcher( DefaultValueProcessorMatcher defaultValueProcessorMatcher ) {
 1039  0
       this.defaultValueProcessorMatcher = defaultValueProcessorMatcher == null ? DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER
 1040  
             : defaultValueProcessorMatcher;
 1041  0
    }
 1042  
 
 1043  
    /**
 1044  
     * Sets the current enclosed type for generic collection transformations.<br>
 1045  
     * [JSON -&gt; Java]
 1046  
     * 
 1047  
     * @param enclosedType the target type for conversion
 1048  
     */
 1049  
    public void setEnclosedType( Class enclosedType ) {
 1050  0
       this.enclosedType = enclosedType;
 1051  0
    }
 1052  
 
 1053  
    /**
 1054  
     * Sets the excludes to use.<br>
 1055  
     * Will set default value ([]) if null.<br>
 1056  
     * [Java -&gt; JSON]
 1057  
     */
 1058  
    public void setExcludes( String[] excludes ) {
 1059  0
       this.excludes = excludes == null ? EMPTY_EXCLUDES : excludes;
 1060  0
    }
 1061  
 
 1062  
    /**
 1063  
     * Activate/Deactivate handling this jettison convention when converting to Java.<br>
 1064  
     * Jettison states that "" (empty string) can be assigned to empty elements (objects), which
 1065  
     * clearly violates the JSON spec.<br>
 1066  
     * [JSON -&gt; Java]
 1067  
     */
 1068  
    public void setHandleJettisonEmptyElement( boolean handleJettisonEmptyElement ) {
 1069  0
       this.handleJettisonEmptyElement = handleJettisonEmptyElement;
 1070  0
    }
 1071  
 
 1072  
    /**
 1073  
     * Activate/Deactivate handling this jettison convention when converting to Java.<br> * Jettison
 1074  
     * states the following JSON {'media':{'title':'hello'}} can be set as a single element JSONArray
 1075  
     * (media is the array).<br>
 1076  
     * [JSON -&gt; Java]
 1077  
     */
 1078  
    public void setHandleJettisonSingleElementArray( boolean handleJettisonSingleElementArray ) {
 1079  0
       this.handleJettisonSingleElementArray = handleJettisonSingleElementArray;
 1080  0
    }
 1081  
 
 1082  
    /**
 1083  
     * Sets if default excludes would be skipped when building.<br>
 1084  
     * [Java -&gt; JSON]
 1085  
     */
 1086  
    public void setIgnoreDefaultExcludes( boolean ignoreDefaultExcludes ) {
 1087  0
       this.ignoreDefaultExcludes = ignoreDefaultExcludes;
 1088  0
    }
 1089  
 
 1090  
    /**
 1091  
     * Sets if JPA Transient annotated methods would be skipped when building.<br>
 1092  
     * [Java -&gt; JSON]
 1093  
     */
 1094  
    public void setIgnoreJPATransient( boolean ignoreJPATransient ) {
 1095  0
       if(ignoreJPATransient) {
 1096  0
          addIgnoreFieldAnnotation("javax.persistence.Transient");
 1097  
       } else {
 1098  0
          removeIgnoreFieldAnnotation("javax.persistence.Transient");
 1099  
       }
 1100  0
    }
 1101  
    
 1102  
    /**
 1103  
     * Adds an annotation that marks a field to be skipped when building.<br>
 1104  
     * [Java -&gt; JSON]
 1105  
     */
 1106  
    public void addIgnoreFieldAnnotation( String annotationClassName ) {
 1107  0
       if( annotationClassName != null && !ignoreFieldAnnotations.contains( annotationClassName )) {
 1108  0
          ignoreFieldAnnotations.add(annotationClassName);
 1109  
       }
 1110  0
    }
 1111  
    
 1112  
    /**
 1113  
     * Adds an annotation that marks a field to be skipped when building.<br>
 1114  
     * [Java -&gt; JSON]
 1115  
     */
 1116  
    public void removeIgnoreFieldAnnotation( String annotationClassName ) {
 1117  0
       if( annotationClassName != null ) ignoreFieldAnnotations.remove(annotationClassName);
 1118  0
    }
 1119  
 
 1120  
    /**
 1121  
     * Removes an annotation that marks a field to be skipped when building.<br>
 1122  
     * [Java -&gt; JSON]
 1123  
     */
 1124  
    public void addIgnoreFieldAnnotation( Class annotationClass ) {
 1125  0
       if( annotationClass != null && !ignoreFieldAnnotations.contains( annotationClass.getName() )) {
 1126  0
          ignoreFieldAnnotations.add(annotationClass.getName());
 1127  
       }
 1128  0
    }
 1129  
    
 1130  
    /**
 1131  
     * Removes an annotation that marks a field to be skipped when building.<br>
 1132  
     * [Java -&gt; JSON]
 1133  
     */
 1134  
    public void removeIgnoreFieldAnnotation( Class annotationClass ) {
 1135  0
       if( annotationClass != null ) ignoreFieldAnnotations.remove(annotationClass.getName());
 1136  0
    }
 1137  
    
 1138  
    /**
 1139  
     * Returns a List of all annotations that mark a field to be skipped when building.<br>
 1140  
     * [Java -&gt; JSON]
 1141  
     */
 1142  
    public List getIgnoreFieldAnnotations() {
 1143  0
       return Collections.unmodifiableList(ignoreFieldAnnotations);
 1144  
    }
 1145  
    
 1146  
    /**
 1147  
     * Sets if transient fields would be skipped when building.<br>
 1148  
     * [Java -&gt; JSON]
 1149  
     */
 1150  
    public void setIgnoreTransientFields( boolean ignoreTransientFields ) {
 1151  0
       this.ignoreTransientFields = ignoreTransientFields;
 1152  0
    }
 1153  
 
 1154  
    /**
 1155  
     * Sets if public fields would be skipped when building.<br>
 1156  
     * [Java -&gt; JSON]
 1157  
     */
 1158  
    public void setIgnorePublicFields( boolean ignorePublicFields ) {
 1159  0
       this.ignorePublicFields = ignorePublicFields;
 1160  0
    }
 1161  
    
 1162  
    /**
 1163  
     * Sets if Javascript compatibility is enabled when building.<br>
 1164  
     * [Java -&gt; JSON]
 1165  
     */
 1166  
    public void setJavascriptCompliant( boolean javascriptCompliant ) {
 1167  0
       this.javascriptCompliant = javascriptCompliant;
 1168  0
    }
 1169  
    
 1170  
    /**
 1171  
     * Sets the JavaIdentifierTransformer to use.<br>
 1172  
     * Will set default value (JavaIdentifierTransformer.NOOP) if null.<br>
 1173  
     * [JSON -&gt; Java]
 1174  
     */
 1175  
    public void setJavaIdentifierTransformer( JavaIdentifierTransformer javaIdentifierTransformer ) {
 1176  0
       this.javaIdentifierTransformer = javaIdentifierTransformer == null ? DEFAULT_JAVA_IDENTIFIER_TRANSFORMER
 1177  
             : javaIdentifierTransformer;
 1178  0
    }
 1179  
 
 1180  
    /**
 1181  
     * Sets a property filter used when serializing to Java.<br>
 1182  
     * [JSON -&gt; Java]
 1183  
     * 
 1184  
     * @param javaPropertyFilter the property filter
 1185  
     */
 1186  
    public void setJavaPropertyFilter( PropertyFilter javaPropertyFilter ) {
 1187  0
       this.javaPropertyFilter = javaPropertyFilter;
 1188  0
    }
 1189  
 
 1190  
    /**
 1191  
     * Sets a PropertyNameProcessorMatcher to use.<br>
 1192  
     * Will set default value (PropertyNameProcessorMatcher.DEFAULT) if null.<br>
 1193  
     * [JSON -&gt; Java]
 1194  
     */
 1195  
    public void setJavaPropertyNameProcessorMatcher( PropertyNameProcessorMatcher propertyNameProcessorMatcher ) {
 1196  0
       this.javaPropertyNameProcessorMatcher = propertyNameProcessorMatcher == null ? DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER
 1197  
             : propertyNameProcessorMatcher;
 1198  0
    }
 1199  
 
 1200  
    /**
 1201  
     * Sets a JsonBeanProcessorMatcher to use.<br>
 1202  
     * Will set default value (JsonBeanProcessorMatcher.DEFAULT) if null.<br>
 1203  
     * [Java -&gt; JSON]
 1204  
     */
 1205  
    public void setJsonBeanProcessorMatcher( JsonBeanProcessorMatcher jsonBeanProcessorMatcher ) {
 1206  0
       this.jsonBeanProcessorMatcher = jsonBeanProcessorMatcher == null ? DEFAULT_JSON_BEAN_PROCESSOR_MATCHER
 1207  
             : jsonBeanProcessorMatcher;
 1208  0
    }
 1209  
 
 1210  
    /**
 1211  
     * Sets a property filter used when serializing to JSON.<br>
 1212  
     * [Java -&gt; JSON]
 1213  
     * 
 1214  
     * @param jsonPropertyFilter the property filter
 1215  
     */
 1216  
    public void setJsonPropertyFilter( PropertyFilter jsonPropertyFilter ) {
 1217  0
       this.jsonPropertyFilter = jsonPropertyFilter;
 1218  0
    }
 1219  
 
 1220  
    /**
 1221  
     * Sets a PropertyNameProcessorMatcher to use.<br>
 1222  
     * Will set default value (PropertyNameProcessorMatcher.DEFAULT) if null.<br>
 1223  
     * [Java -&gt; JSON]
 1224  
     */
 1225  
    public void setJsonPropertyNameProcessorMatcher( PropertyNameProcessorMatcher propertyNameProcessorMatcher ) {
 1226  0
       this.jsonPropertyNameProcessorMatcher = propertyNameProcessorMatcher == null ? DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER
 1227  
             : propertyNameProcessorMatcher;
 1228  0
    }
 1229  
 
 1230  
    /**
 1231  
     * Sets a JsonValueProcessorMatcher to use.<br>
 1232  
     * Will set default value (JsonValueProcessorMatcher.DEFAULT) if null.<br>
 1233  
     * [Java -&gt; JSON]
 1234  
     */
 1235  
    public void setJsonValueProcessorMatcher( JsonValueProcessorMatcher jsonValueProcessorMatcher ) {
 1236  0
       this.jsonValueProcessorMatcher = jsonValueProcessorMatcher == null ? DEFAULT_JSON_VALUE_PROCESSOR_MATCHER
 1237  
             : jsonValueProcessorMatcher;
 1238  0
    }
 1239  
    
 1240  
    /**
 1241  
     * Sets the NewBeanInstanceStrategy to use.<br>
 1242  
     * Will set default value (NewBeanInstanceStrategy.DEFAULT) if null.<br>
 1243  
     * [JSON -&gt; Java]
 1244  
     */
 1245  
    public void setNewBeanInstanceStrategy( NewBeanInstanceStrategy newBeanInstanceStrategy ) {
 1246  0
       this.newBeanInstanceStrategy = newBeanInstanceStrategy == null ? DEFAULT_NEW_BEAN_INSTANCE_STRATEGY
 1247  
             : newBeanInstanceStrategy;
 1248  0
    }
 1249  
    
 1250  
    /**
 1251  
     * Sets a PropertyExclusionClassMatcher to use.<br>
 1252  
     * Will set default value (PropertyExclusionClassMatcher.DEFAULT) if null.<br>
 1253  
     * [Java -&gt; JSON]
 1254  
     */
 1255  
    public void setPropertyExclusionClassMatcher( PropertyExclusionClassMatcher propertyExclusionClassMatcher ) {
 1256  0
       this.propertyExclusionClassMatcher = propertyExclusionClassMatcher == null ? DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER
 1257  
             : propertyExclusionClassMatcher;
 1258  0
    }
 1259  
    
 1260  
    /**
 1261  
     * Sets a PropertyNameProcessorMatcher to use.<br>
 1262  
     * Will set default value (PropertyNameProcessorMatcher.DEFAULT) if null.<br>
 1263  
     * [JSON -&gt; Java]
 1264  
     * 
 1265  
     * @deprecated use setJavaPropertyNameProcessorMatcher() instead
 1266  
     */
 1267  
    public void setPropertyNameProcessorMatcher( PropertyNameProcessorMatcher propertyNameProcessorMatcher ) {
 1268  0
       setJavaPropertyNameProcessorMatcher( propertyNameProcessorMatcher );
 1269  0
    }
 1270  
 
 1271  
    /**
 1272  
     * Sets a PropertySetStrategy to use.<br>
 1273  
     * Will set default value (PropertySetStrategy.DEFAULT) if null.<br>
 1274  
     * [JSON -&gt; Java]
 1275  
     */
 1276  
    public void setPropertySetStrategy( PropertySetStrategy propertySetStrategy ) {
 1277  0
       this.propertySetStrategy = propertySetStrategy;
 1278  0
    }
 1279  
 
 1280  
    /**
 1281  
     * Sets the current root Class.<br>
 1282  
     * [JSON -&gt; Java]
 1283  
     * 
 1284  
     * @param rootClass the target class for conversion
 1285  
     */
 1286  
    public void setRootClass( Class rootClass ) {
 1287  0
       this.rootClass = rootClass;
 1288  0
    }
 1289  
 
 1290  
    /**
 1291  
     * Sets if property name as JavaIndetifier transformations would be skipped.<br>
 1292  
     * [JSON -&gt; Java]
 1293  
     */
 1294  
    public void setSkipJavaIdentifierTransformationInMapKeys( boolean skipJavaIdentifierTransformationInMapKeys ) {
 1295  0
       this.skipJavaIdentifierTransformationInMapKeys = skipJavaIdentifierTransformationInMapKeys;
 1296  0
    }
 1297  
 
 1298  
    /**
 1299  
     * Removes a DefaultValueProcessor.<br>
 1300  
     * [Java -&gt; JSON]
 1301  
     * 
 1302  
     * @param target a class used for searching a DefaultValueProcessor.
 1303  
     */
 1304  
    public void unregisterDefaultValueProcessor( Class target ) {
 1305  0
       if( target != null ) {
 1306  0
          defaultValueMap.remove( target );
 1307  
       }
 1308  0
    }
 1309  
 
 1310  
    /**
 1311  
     * Removes a PropertyNameProcessor.<br>
 1312  
     * [JSON -&gt; Java]
 1313  
     * 
 1314  
     * @param target a class used for searching a PropertyNameProcessor.
 1315  
     */
 1316  
    public void unregisterJavaPropertyNameProcessor( Class target ) {
 1317  0
       if( target != null ) {
 1318  0
          javaPropertyNameProcessorMap.remove( target );
 1319  
       }
 1320  0
    }
 1321  
    
 1322  
    /**
 1323  
     * Removes a JsonBeanProcessor.<br>
 1324  
     * [Java -&gt; JSON]
 1325  
     * 
 1326  
     * @param target a class used for searching a JsonBeanProcessor.
 1327  
     */
 1328  
    public void unregisterJsonBeanProcessor( Class target ) {
 1329  0
       if( target != null ) {
 1330  0
          beanProcessorMap.remove( target );
 1331  
       }
 1332  0
    }
 1333  
 
 1334  
    /**
 1335  
     * Removes a PropertyNameProcessor.<br>
 1336  
     * [Java -&gt; JSON]
 1337  
     * 
 1338  
     * @param target a class used for searching a PropertyNameProcessor.
 1339  
     */
 1340  
    public void unregisterJsonPropertyNameProcessor( Class target ) {
 1341  0
       if( target != null ) {
 1342  0
          jsonPropertyNameProcessorMap.remove( target );
 1343  
       }
 1344  0
    }
 1345  
 
 1346  
    /**
 1347  
     * Removes a JsonValueProcessor.<br>
 1348  
     * [Java -&gt; JSON]
 1349  
     * 
 1350  
     * @param propertyType a class used for searching a JsonValueProcessor.
 1351  
     */
 1352  
    public void unregisterJsonValueProcessor( Class propertyType ) {
 1353  0
       if( propertyType != null ) {
 1354  0
          typeMap.remove( propertyType );
 1355  
       }
 1356  0
    }
 1357  
 
 1358  
    /**
 1359  
     * Removes a JsonValueProcessor.<br>
 1360  
     * [Java -&gt; JSON]
 1361  
     * 
 1362  
     * @param beanClass the class to which the property may belong
 1363  
     * @param propertyType the type of the property
 1364  
     */
 1365  
    public void unregisterJsonValueProcessor( Class beanClass, Class propertyType ) {
 1366  0
       if( beanClass != null && propertyType != null ) {
 1367  0
          beanTypeMap.remove( beanClass, propertyType );
 1368  
       }
 1369  0
    }
 1370  
 
 1371  
    /**
 1372  
     * Removes a JsonValueProcessor.<br>
 1373  
     * [Java -&gt; JSON]
 1374  
     * 
 1375  
     * @param beanClass the class to which the property may belong
 1376  
     * @param key the name of the property which may belong to the target class
 1377  
     */
 1378  
    public void unregisterJsonValueProcessor( Class beanClass, String key ) {
 1379  0
       if( beanClass != null && key != null ) {
 1380  0
          beanKeyMap.remove( beanClass, key );
 1381  
       }
 1382  0
    }
 1383  
 
 1384  
    /**
 1385  
     * Removes a JsonValueProcessor.<br>
 1386  
     * [Java -&gt; JSON]
 1387  
     * 
 1388  
     * @param key the name of the property which may belong to the target class
 1389  
     */
 1390  
    public void unregisterJsonValueProcessor( String key ) {
 1391  0
       if( key != null ) {
 1392  0
          keyMap.remove( key );
 1393  
       }
 1394  0
    }
 1395  
 
 1396  
    /**
 1397  
     * Removes a property exclusion assigned to the target class.<br>
 1398  
     * [Java -&gt; JSON]
 1399  
     * 
 1400  
     * @param target a class used for searching property exclusions.
 1401  
     * @param propertyName the name of the property to be removed from the exclusion list.
 1402  
     */
 1403  
    public void unregisterPropertyExclusion( Class target, String propertyName ) {
 1404  0
       if( target != null && propertyName != null ) {
 1405  0
          Set set = (Set) exclusionMap.get( target );
 1406  0
          if( set == null ) {
 1407  0
             set = new HashSet();
 1408  0
             exclusionMap.put( target, set );
 1409  
          }
 1410  0
          set.remove( propertyName );
 1411  
       }
 1412  0
    }
 1413  
    
 1414  
    /**
 1415  
     * Removes all property exclusions assigned to the target class.<br>
 1416  
     * [Java -&gt; JSON]
 1417  
     * 
 1418  
     * @param target a class used for searching property exclusions.
 1419  
     */
 1420  
    public void unregisterPropertyExclusions( Class target ) {
 1421  0
       if( target != null ) {
 1422  0
          Set set = (Set) exclusionMap.get( target );
 1423  0
          if( set != null ) {
 1424  0
             set.clear();
 1425  
          }
 1426  
       }
 1427  0
    }
 1428  
    
 1429  
    /**
 1430  
     * Removes a PropertyNameProcessor.<br>
 1431  
     * [JSON -&gt; Java]
 1432  
     * 
 1433  
     * @param target a class used for searching a PropertyNameProcessor.
 1434  
     * 
 1435  
     * @deprecated use unregisterJavaPropertyNameProcessor() instead
 1436  
     */
 1437  
    public void unregisterPropertyNameProcessor( Class target ) {
 1438  0
       unregisterJavaPropertyNameProcessor( target );
 1439  0
    }
 1440  
 }