1 package com.fasterxml.jackson.databind.deser.impl;
2
3 import com.fasterxml.jackson.databind.*;
4 import com.fasterxml.jackson.databind.deser.NullValueProvider;
5 import com.fasterxml.jackson.databind.exc.InvalidNullException;
6 import com.fasterxml.jackson.databind.util.AccessPattern;
7
8 /**
9  * Simple {@link NullValueProvider} that will always throw a
10  * {@link InvalidNullException} when a null is encountered.
11  */

12 public class NullsConstantProvider
13     implements NullValueProvider, java.io.Serializable
14 {
15     private static final long serialVersionUID = 1L;
16
17     private final static NullsConstantProvider SKIPPER = new NullsConstantProvider(null);
18
19     private final static NullsConstantProvider NULLER = new NullsConstantProvider(null);
20     
21     protected final Object _nullValue;
22
23     protected final AccessPattern _access;
24
25     protected NullsConstantProvider(Object nvl) {
26         _nullValue = nvl;
27         _access = (_nullValue == null) ? AccessPattern.ALWAYS_NULL
28                 : AccessPattern.CONSTANT;
29     }
30
31     /**
32      * Static accessor for a stateless instance used as marker, to indicate
33      * that all input `null` values should be skipped (ignored), so that
34      * no corresponding property value is set (with POJOs), and no content
35      * values (array/Collection elements, Map entries) are added.
36      */

37     public static NullsConstantProvider skipper() {
38         return SKIPPER;
39     }
40
41     public static NullsConstantProvider nuller() {
42         return NULLER;
43     }
44
45     public static NullsConstantProvider forValue(Object nvl) {
46         if (nvl == null) {
47             return NULLER;
48         }
49         return new NullsConstantProvider(nvl);
50     }
51
52     /**
53      * Utility method that can be used to check if given null value provider
54      * is "skipper", marker provider that means that all input `null`s should
55      * be skipped (ignored), instead of converted
56      */

57     public static boolean isSkipper(NullValueProvider p) {
58         return (p == SKIPPER);
59     }
60
61     /**
62      * Utility method that can be used to check if given null value provider
63      * is "nuller", no-operation provider that will always simply return
64      * Java `nullfor any and all input `null`s.
65      */

66     public static boolean isNuller(NullValueProvider p) {
67         return (p == NULLER);
68     }
69     
70     @Override
71     public AccessPattern getNullAccessPattern() {
72         return _access;
73     }
74     
75     @Override
76     public Object getNullValue(DeserializationContext ctxt) {
77         return _nullValue;
78     }
79 }
80