• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.deser.std;
2 
3 import java.nio.ByteBuffer;
4 import java.util.*;
5 import java.util.concurrent.atomic.AtomicBoolean;
6 
7 import com.fasterxml.jackson.databind.*;
8 
9 /**
10  * Container class that contains serializers for JDK types that
11  * require special handling for some reason.
12  */
13 public class JdkDeserializers
14 {
15     private final static HashSet<String> _classNames = new HashSet<String>();
16     static {
17         // note: can skip primitive types; other ways to check them:
18         Class<?>[] types = new Class<?>[] {
19                 UUID.class,
20                 AtomicBoolean.class,
21                 StackTraceElement.class,
22                 ByteBuffer.class,
23                 Void.class
24         };
cls.getName()25         for (Class<?> cls : types) { _classNames.add(cls.getName()); }
cls.getName()26         for (Class<?> cls : FromStringDeserializer.types()) { _classNames.add(cls.getName()); }
27     }
28 
find(Class<?> rawType, String clsName)29     public static JsonDeserializer<?> find(Class<?> rawType, String clsName)
30     {
31         if (_classNames.contains(clsName)) {
32             JsonDeserializer<?> d = FromStringDeserializer.findDeserializer(rawType);
33             if (d != null) {
34                 return d;
35             }
36             if (rawType == UUID.class) {
37                 return new UUIDDeserializer();
38             }
39             if (rawType == StackTraceElement.class) {
40                 return new StackTraceElementDeserializer();
41             }
42             if (rawType == AtomicBoolean.class) {
43                 // (note: AtomicInteger/Long work due to single-arg constructor. For now?
44                 return new AtomicBooleanDeserializer();
45             }
46             if (rawType == ByteBuffer.class) {
47                 return new ByteBufferDeserializer();
48             }
49             if (rawType == Void.class) {
50                 return NullifyingDeserializer.instance;
51             }
52         }
53         return null;
54     }
55 
56     // @since 2.11
hasDeserializerFor(Class<?> rawType)57     public static boolean hasDeserializerFor(Class<?> rawType) {
58         return _classNames.contains(rawType.getName());
59     }
60 }
61