View Javadoc

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     public static final DefaultValueProcessorMatcher DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER = DefaultValueProcessorMatcher.DEFAULT;
56     public static final JsonBeanProcessorMatcher DEFAULT_JSON_BEAN_PROCESSOR_MATCHER = JsonBeanProcessorMatcher.DEFAULT;
57     public static final JsonValueProcessorMatcher DEFAULT_JSON_VALUE_PROCESSOR_MATCHER = JsonValueProcessorMatcher.DEFAULT;
58     public static final NewBeanInstanceStrategy DEFAULT_NEW_BEAN_INSTANCE_STRATEGY = NewBeanInstanceStrategy.DEFAULT;
59     public static final PropertyExclusionClassMatcher DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER = PropertyExclusionClassMatcher.DEFAULT;
60     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     private static final Class DEFAULT_COLLECTION_TYPE = List.class;
65     private static final CycleDetectionStrategy DEFAULT_CYCLE_DETECTION_STRATEGY = CycleDetectionStrategy.STRICT;
66     private static final String[] DEFAULT_EXCLUDES = new String[] { "class", "declaringClass", "metaClass" };
67     private static final JavaIdentifierTransformer DEFAULT_JAVA_IDENTIFIER_TRANSFORMER = JavaIdentifierTransformer.NOOP;
68     private static final DefaultValueProcessor DEFAULT_VALUE_PROCESSOR = new DefaultDefaultValueProcessor();
69     private static final String[] EMPTY_EXCLUDES = new String[0];
70  
71     /** Array conversion mode */
72     private int arrayMode = MODE_LIST;
73     private MultiKeyMap beanKeyMap = new MultiKeyMap();
74     private Map beanProcessorMap = new HashMap();
75     private MultiKeyMap beanTypeMap = new MultiKeyMap();
76     /** Map of attribute/class */
77     private Map classMap;
78     private Class collectionType = DEFAULT_COLLECTION_TYPE;
79     private CycleDetectionStrategy cycleDetectionStrategy = DEFAULT_CYCLE_DETECTION_STRATEGY;
80     private Map defaultValueMap = new HashMap();
81     private DefaultValueProcessorMatcher defaultValueProcessorMatcher = DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER;
82     private Class enclosedType;
83     private List eventListeners = new ArrayList();
84     private String[] excludes = EMPTY_EXCLUDES;
85     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     private boolean ignorePublicFields = true;
92     private boolean javascriptCompliant;
93     private JavaIdentifierTransformer javaIdentifierTransformer = DEFAULT_JAVA_IDENTIFIER_TRANSFORMER;
94     private PropertyFilter javaPropertyFilter;
95     private Map javaPropertyNameProcessorMap = new HashMap();
96     private PropertyNameProcessorMatcher javaPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
97     private JsonBeanProcessorMatcher jsonBeanProcessorMatcher = DEFAULT_JSON_BEAN_PROCESSOR_MATCHER;
98     private PropertyFilter jsonPropertyFilter;
99     private Map jsonPropertyNameProcessorMap = new HashMap();
100    private PropertyNameProcessorMatcher jsonPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
101    private JsonValueProcessorMatcher jsonValueProcessorMatcher = DEFAULT_JSON_VALUE_PROCESSOR_MATCHER;
102    private Map keyMap = new HashMap();
103    private NewBeanInstanceStrategy newBeanInstanceStrategy = DEFAULT_NEW_BEAN_INSTANCE_STRATEGY;
104    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    private Map typeMap = new HashMap();
111    private List ignoreFieldAnnotations = new ArrayList();
112    private boolean allowNonStringKeys = false;
113 
114    public JsonConfig() {
115    }
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       if( !eventListeners.contains( listener ) ) {
130          eventListeners.add( listener );
131       }
132    }
133 
134    /**
135     * Removes all registered PropertyNameProcessors.<br>
136     * [JSON -&gt; Java]
137     */
138    public void clearJavaPropertyNameProcessors() {
139       javaPropertyNameProcessorMap.clear();
140    }
141 
142    /**
143     * Removes all registered JsonBeanProcessors.<br>
144     * [Java -&gt; JSON]
145     */
146    public void clearJsonBeanProcessors() {
147       beanProcessorMap.clear();
148    }
149 
150    /**
151     * Removes all registered listener for JSON Events.<br>
152     * [Java -&gt; JSON]
153     */
154    public synchronized void clearJsonEventListeners() {
155       eventListeners.clear();
156    }
157 
158    /**
159     * Removes all registered PropertyNameProcessors.<br>
160     * [Java -&gt; JSON]
161     */
162    public void clearJsonPropertyNameProcessors() {
163       jsonPropertyNameProcessorMap.clear();
164    }   
165    
166    /**
167     * Removes all registered JsonValueProcessors.<br>
168     * [Java -&gt; JSON]
169     */
170    public void clearJsonValueProcessors() {
171       beanKeyMap.clear();
172       beanTypeMap.clear();
173       keyMap.clear();
174       typeMap.clear();
175    }
176    
177    /**
178     * Removes all property exclusions registered per class.<br>
179     * [Java -&gt; JSON]
180     */
181    public void clearPropertyExclusions() {
182       exclusionMap.clear();
183    }
184 
185    /**
186     * Removes all registered PropertyNameProcessors.<br>
187     * [JSON -&gt; Java]
188     * 
189     * @deprecated use clearJavaPropertyNameProcessors() instead
190     */
191    public void clearPropertyNameProcessors() {
192       clearJavaPropertyNameProcessors();
193    }
194 
195    public JsonConfig copy() {
196       JsonConfig jsc = new JsonConfig();
197       jsc.beanKeyMap.putAll( beanKeyMap );
198       jsc.beanTypeMap.putAll( beanTypeMap );
199       jsc.classMap = new HashMap();
200       if( classMap != null ) {
201          jsc.classMap.putAll( classMap );
202       }
203       jsc.cycleDetectionStrategy = cycleDetectionStrategy;
204       if( eventListeners != null ) {
205          jsc.eventListeners.addAll( eventListeners );
206       }
207       if( excludes != null ) {
208          jsc.excludes = new String[excludes.length];
209          System.arraycopy( excludes, 0, jsc.excludes, 0, excludes.length );
210       }
211       jsc.handleJettisonEmptyElement = handleJettisonEmptyElement;
212       jsc.handleJettisonSingleElementArray = handleJettisonSingleElementArray;
213       jsc.ignoreDefaultExcludes = ignoreDefaultExcludes;
214       jsc.ignoreTransientFields = ignoreTransientFields;
215       jsc.ignorePublicFields = ignorePublicFields;
216       jsc.javaIdentifierTransformer = javaIdentifierTransformer;
217       jsc.javascriptCompliant = javascriptCompliant;
218       jsc.keyMap.putAll( keyMap );
219       jsc.beanProcessorMap.putAll( beanProcessorMap );
220       jsc.rootClass = rootClass;
221       jsc.skipJavaIdentifierTransformationInMapKeys = skipJavaIdentifierTransformationInMapKeys;
222       jsc.triggerEvents = triggerEvents;
223       jsc.typeMap.putAll( typeMap );
224       jsc.jsonPropertyFilter = jsonPropertyFilter;
225       jsc.javaPropertyFilter = javaPropertyFilter;
226       jsc.jsonBeanProcessorMatcher = jsonBeanProcessorMatcher;
227       jsc.newBeanInstanceStrategy = newBeanInstanceStrategy;
228       jsc.defaultValueProcessorMatcher = defaultValueProcessorMatcher;
229       jsc.defaultValueMap.putAll( defaultValueMap );
230       jsc.propertySetStrategy = propertySetStrategy;
231       //jsc.ignoreJPATransient = ignoreJPATransient;
232       jsc.collectionType = collectionType;
233       jsc.enclosedType = enclosedType;
234       jsc.jsonValueProcessorMatcher = jsonValueProcessorMatcher;
235       jsc.javaPropertyNameProcessorMatcher = javaPropertyNameProcessorMatcher;
236       jsc.javaPropertyNameProcessorMap.putAll( javaPropertyNameProcessorMap );
237       jsc.jsonPropertyNameProcessorMatcher = jsonPropertyNameProcessorMatcher;
238       jsc.jsonPropertyNameProcessorMap.putAll( jsonPropertyNameProcessorMap );
239       jsc.propertyExclusionClassMatcher = propertyExclusionClassMatcher;
240       jsc.exclusionMap.putAll(  exclusionMap );
241       jsc.ignoreFieldAnnotations.addAll( ignoreFieldAnnotations );
242       jsc.allowNonStringKeys = allowNonStringKeys;
243       return jsc;
244    }
245 
246    /**
247     * Disables event triggering when building.<br>
248     * [Java -&gt; JSON]
249     */
250    public void disableEventTriggering() {
251       triggerEvents = false;
252    }
253 
254    /**
255     * Enables event triggering when building.<br>
256     * [Java -&gt; JSON]
257     */
258    public void enableEventTriggering() {
259       triggerEvents = true;
260    }
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       if( !defaultValueMap.isEmpty() ) {
271          Object key = defaultValueProcessorMatcher.getMatch( target, defaultValueMap.keySet() );
272          DefaultValueProcessor processor = (DefaultValueProcessor) defaultValueMap.get( key );
273          if( processor != null ) {
274             return processor;
275          }
276       }
277       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       if( !javaPropertyNameProcessorMap.isEmpty() ) {
289          Object key = javaPropertyNameProcessorMatcher.getMatch( beanClass, javaPropertyNameProcessorMap.keySet() );
290          return (PropertyNameProcessor) javaPropertyNameProcessorMap.get( key );
291 
292       }
293       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       if( !beanProcessorMap.isEmpty() ) {
305          Object key = jsonBeanProcessorMatcher.getMatch( target, beanProcessorMap.keySet() );
306          return (JsonBeanProcessor) beanProcessorMap.get( key );
307       }
308       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       if( !jsonPropertyNameProcessorMap.isEmpty() ) {
320          Object key = jsonPropertyNameProcessorMatcher.getMatch( beanClass, jsonPropertyNameProcessorMap.keySet() );
321          return (PropertyNameProcessor) jsonPropertyNameProcessorMap.get( key );
322 
323       }
324       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       if( !typeMap.isEmpty() ) {
336          Object key = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
337          return (JsonValueProcessor) typeMap.get( key );
338 
339       }
340       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       JsonValueProcessor jsonValueProcessor = null;
361       jsonValueProcessor = (JsonValueProcessor) beanKeyMap.get( beanClass, key );
362       if( jsonValueProcessor != null ) {
363          return jsonValueProcessor;
364       }
365 
366       jsonValueProcessor = (JsonValueProcessor) beanTypeMap.get( beanClass, propertyType );
367       if( jsonValueProcessor != null ) {
368          return jsonValueProcessor;
369       }
370 
371       jsonValueProcessor = (JsonValueProcessor) keyMap.get( key );
372       if( jsonValueProcessor != null ) {
373          return jsonValueProcessor;
374       }
375 
376       Object tkey = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
377       jsonValueProcessor = (JsonValueProcessor) typeMap.get( tkey );
378       if( jsonValueProcessor != null ) {
379          return jsonValueProcessor;
380       }
381 
382       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       JsonValueProcessor jsonValueProcessor = null;
400       jsonValueProcessor = (JsonValueProcessor) keyMap.get( key );
401       if( jsonValueProcessor != null ) {
402          return jsonValueProcessor;
403       }
404 
405       Object tkey = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
406       jsonValueProcessor = (JsonValueProcessor) typeMap.get( tkey );
407       if( jsonValueProcessor != null ) {
408          return jsonValueProcessor;
409       }
410 
411       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       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       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       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       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       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       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       return enclosedType;
483    }
484 
485    /**
486     * Returns the configured properties for exclusion. <br>
487     * [Java -&gt; JSON]
488     */
489    public String[] getExcludes() {
490       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       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       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       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       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       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       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       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       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       Collection exclusions = new HashSet();
568       for( int i = 0; i < excludes.length; i++ ) {
569          String exclusion = excludes[i];
570          if( !StringUtils.isBlank( excludes[i] ) ) {
571             exclusions.add( exclusion.trim() );
572          }
573       }
574 
575       if( !ignoreDefaultExcludes ) {
576          for( int i = 0; i < DEFAULT_EXCLUDES.length; i++ ) {
577             if( !exclusions.contains( DEFAULT_EXCLUDES[i] ) ) {
578                exclusions.add( DEFAULT_EXCLUDES[i] );
579             }
580          }
581       }
582 
583       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       if( target == null ) {
593          return getMergedExcludes();
594       }
595 
596       Collection exclusionSet = getMergedExcludes();
597       if( !exclusionMap.isEmpty() ) {
598          Object key = propertyExclusionClassMatcher.getMatch( target, exclusionMap.keySet() );
599          Set set = (Set) exclusionMap.get( key );
600          if( set != null && !set.isEmpty() ) {
601             for( Iterator i = set.iterator(); i.hasNext(); ) {
602                Object e = i.next();
603                if( !exclusionSet.contains( e ) ) {
604                   exclusionSet.add( e );
605                }
606             }
607          }
608       }
609 
610       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       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       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       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       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       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       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       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       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       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       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       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       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       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       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       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       if( target != null && defaultValueProcessor != null ) {
762          defaultValueMap.put( target, defaultValueProcessor );
763       }
764    }
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       if( target != null && propertyNameProcessor != null ) {
775          javaPropertyNameProcessorMap.put( target, propertyNameProcessor );
776       }
777    }
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       if( target != null && jsonBeanProcessor != null ) {
788          beanProcessorMap.put( target, jsonBeanProcessor );
789       }
790    }
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       if( target != null && propertyNameProcessor != null ) {
801          jsonPropertyNameProcessorMap.put( target, propertyNameProcessor );
802       }
803    }
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       if( beanClass != null && propertyType != null && jsonValueProcessor != null ) {
815          beanTypeMap.put( beanClass, propertyType, jsonValueProcessor );
816       }
817    }
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       if( propertyType != null && jsonValueProcessor != null ) {
828          typeMap.put( propertyType, jsonValueProcessor );
829       }
830    }
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       if( beanClass != null && key != null && jsonValueProcessor != null ) {
842          beanKeyMap.put( beanClass, key, jsonValueProcessor );
843       }
844    }
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       if( key != null && jsonValueProcessor != null ) {
855          keyMap.put( key, jsonValueProcessor );
856       }
857    }
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       if( target != null && propertyName != null ) {
868          Set set = (Set) exclusionMap.get( target );
869          if( set == null ){
870             set = new HashSet();
871             exclusionMap.put(  target, set );
872          }
873          if( !set.contains( propertyName )){
874             set.add(propertyName );
875          }
876       }
877    }
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       if( target != null && properties != null && properties.length > 0 ) {
888          Set set = (Set) exclusionMap.get( target );
889          if( set == null ) {
890             set = new HashSet();
891             exclusionMap.put( target, set );
892          }
893          for( int i = 0; i < properties.length; i++ ) {
894             if( !set.contains( properties[i] ) ) {
895                set.add( properties[i] );
896             }
897          }
898       }
899    }
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       registerJavaPropertyNameProcessor( target, propertyNameProcessor );
912    }
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       eventListeners.remove( listener );
923    }
924 
925    /**
926     * Resets all values to its default state.
927     */
928    public void reset() {
929       excludes = EMPTY_EXCLUDES;
930       ignoreDefaultExcludes = false;
931       ignoreTransientFields = false;
932       ignorePublicFields = true;
933       javascriptCompliant = false;
934       javaIdentifierTransformer = DEFAULT_JAVA_IDENTIFIER_TRANSFORMER;
935       cycleDetectionStrategy = DEFAULT_CYCLE_DETECTION_STRATEGY;
936       skipJavaIdentifierTransformationInMapKeys = false;
937       triggerEvents = false;
938       handleJettisonEmptyElement = false;
939       handleJettisonSingleElementArray = false;
940       arrayMode = MODE_LIST;
941       rootClass = null;
942       classMap = null;
943       keyMap.clear();
944       typeMap.clear();
945       beanKeyMap.clear();
946       beanTypeMap.clear();
947       jsonPropertyFilter = null;
948       javaPropertyFilter = null;
949       jsonBeanProcessorMatcher = DEFAULT_JSON_BEAN_PROCESSOR_MATCHER;
950       newBeanInstanceStrategy = DEFAULT_NEW_BEAN_INSTANCE_STRATEGY;
951       defaultValueProcessorMatcher = DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER;
952       defaultValueMap.clear();
953       propertySetStrategy = null/* DEFAULT_PROPERTY_SET_STRATEGY */;
954       //ignoreJPATransient = false;
955       collectionType = DEFAULT_COLLECTION_TYPE;
956       enclosedType = null;
957       jsonValueProcessorMatcher = DEFAULT_JSON_VALUE_PROCESSOR_MATCHER;
958       javaPropertyNameProcessorMap.clear();
959       javaPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
960       jsonPropertyNameProcessorMap.clear();
961       jsonPropertyNameProcessorMatcher = DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER;
962       beanProcessorMap.clear();
963       propertyExclusionClassMatcher = DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER;
964       exclusionMap.clear();
965       ignoreFieldAnnotations.clear();
966       allowNonStringKeys = false;
967    }
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       this.allowNonStringKeys = allowNonStringKeys;
975    }
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       if( arrayMode == MODE_OBJECT_ARRAY ) {
986          this.arrayMode = arrayMode;
987       } else if( arrayMode == MODE_SET ) {
988          this.arrayMode = arrayMode;
989          this.collectionType = Set.class;
990       } else {
991          this.arrayMode = MODE_LIST;
992          this.enclosedType = DEFAULT_COLLECTION_TYPE;
993       }
994    }
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       this.classMap = classMap;
1004    }
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       if( collectionType != null ) {
1014          if( !Collection.class.isAssignableFrom( collectionType ) ) {
1015             throw new JSONException( "The configured collectionType is not a Collection: " + collectionType.getName() );
1016          }
1017          this.collectionType = collectionType;
1018       } else {
1019          collectionType = DEFAULT_COLLECTION_TYPE;
1020       }
1021    }
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       this.cycleDetectionStrategy = cycleDetectionStrategy == null ? DEFAULT_CYCLE_DETECTION_STRATEGY
1030             : cycleDetectionStrategy;
1031    }
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       this.defaultValueProcessorMatcher = defaultValueProcessorMatcher == null ? DEFAULT_DEFAULT_VALUE_PROCESSOR_MATCHER
1040             : defaultValueProcessorMatcher;
1041    }
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       this.enclosedType = enclosedType;
1051    }
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       this.excludes = excludes == null ? EMPTY_EXCLUDES : excludes;
1060    }
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       this.handleJettisonEmptyElement = handleJettisonEmptyElement;
1070    }
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       this.handleJettisonSingleElementArray = handleJettisonSingleElementArray;
1080    }
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       this.ignoreDefaultExcludes = ignoreDefaultExcludes;
1088    }
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       if(ignoreJPATransient) {
1096          addIgnoreFieldAnnotation("javax.persistence.Transient");
1097       } else {
1098          removeIgnoreFieldAnnotation("javax.persistence.Transient");
1099       }
1100    }
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       if( annotationClassName != null && !ignoreFieldAnnotations.contains( annotationClassName )) {
1108          ignoreFieldAnnotations.add(annotationClassName);
1109       }
1110    }
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       if( annotationClassName != null ) ignoreFieldAnnotations.remove(annotationClassName);
1118    }
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       if( annotationClass != null && !ignoreFieldAnnotations.contains( annotationClass.getName() )) {
1126          ignoreFieldAnnotations.add(annotationClass.getName());
1127       }
1128    }
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       if( annotationClass != null ) ignoreFieldAnnotations.remove(annotationClass.getName());
1136    }
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       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       this.ignoreTransientFields = ignoreTransientFields;
1152    }
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       this.ignorePublicFields = ignorePublicFields;
1160    }
1161    
1162    /**
1163     * Sets if Javascript compatibility is enabled when building.<br>
1164     * [Java -&gt; JSON]
1165     */
1166    public void setJavascriptCompliant( boolean javascriptCompliant ) {
1167       this.javascriptCompliant = javascriptCompliant;
1168    }
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       this.javaIdentifierTransformer = javaIdentifierTransformer == null ? DEFAULT_JAVA_IDENTIFIER_TRANSFORMER
1177             : javaIdentifierTransformer;
1178    }
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       this.javaPropertyFilter = javaPropertyFilter;
1188    }
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       this.javaPropertyNameProcessorMatcher = propertyNameProcessorMatcher == null ? DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER
1197             : propertyNameProcessorMatcher;
1198    }
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       this.jsonBeanProcessorMatcher = jsonBeanProcessorMatcher == null ? DEFAULT_JSON_BEAN_PROCESSOR_MATCHER
1207             : jsonBeanProcessorMatcher;
1208    }
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       this.jsonPropertyFilter = jsonPropertyFilter;
1218    }
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       this.jsonPropertyNameProcessorMatcher = propertyNameProcessorMatcher == null ? DEFAULT_PROPERTY_NAME_PROCESSOR_MATCHER
1227             : propertyNameProcessorMatcher;
1228    }
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       this.jsonValueProcessorMatcher = jsonValueProcessorMatcher == null ? DEFAULT_JSON_VALUE_PROCESSOR_MATCHER
1237             : jsonValueProcessorMatcher;
1238    }
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       this.newBeanInstanceStrategy = newBeanInstanceStrategy == null ? DEFAULT_NEW_BEAN_INSTANCE_STRATEGY
1247             : newBeanInstanceStrategy;
1248    }
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       this.propertyExclusionClassMatcher = propertyExclusionClassMatcher == null ? DEFAULT_PROPERTY_EXCLUSION_CLASS_MATCHER
1257             : propertyExclusionClassMatcher;
1258    }
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       setJavaPropertyNameProcessorMatcher( propertyNameProcessorMatcher );
1269    }
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       this.propertySetStrategy = propertySetStrategy;
1278    }
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       this.rootClass = rootClass;
1288    }
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       this.skipJavaIdentifierTransformationInMapKeys = skipJavaIdentifierTransformationInMapKeys;
1296    }
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       if( target != null ) {
1306          defaultValueMap.remove( target );
1307       }
1308    }
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       if( target != null ) {
1318          javaPropertyNameProcessorMap.remove( target );
1319       }
1320    }
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       if( target != null ) {
1330          beanProcessorMap.remove( target );
1331       }
1332    }
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       if( target != null ) {
1342          jsonPropertyNameProcessorMap.remove( target );
1343       }
1344    }
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       if( propertyType != null ) {
1354          typeMap.remove( propertyType );
1355       }
1356    }
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       if( beanClass != null && propertyType != null ) {
1367          beanTypeMap.remove( beanClass, propertyType );
1368       }
1369    }
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       if( beanClass != null && key != null ) {
1380          beanKeyMap.remove( beanClass, key );
1381       }
1382    }
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       if( key != null ) {
1392          keyMap.remove( key );
1393       }
1394    }
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       if( target != null && propertyName != null ) {
1405          Set set = (Set) exclusionMap.get( target );
1406          if( set == null ) {
1407             set = new HashSet();
1408             exclusionMap.put( target, set );
1409          }
1410          set.remove( propertyName );
1411       }
1412    }
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       if( target != null ) {
1422          Set set = (Set) exclusionMap.get( target );
1423          if( set != null ) {
1424             set.clear();
1425          }
1426       }
1427    }
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       unregisterJavaPropertyNameProcessor( target );
1439    }
1440 }