• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.json;
2 
3 import com.fasterxml.jackson.core.JsonFactory;
4 import com.fasterxml.jackson.core.Version;
5 import com.fasterxml.jackson.core.json.JsonReadFeature;
6 import com.fasterxml.jackson.core.json.JsonWriteFeature;
7 
8 import com.fasterxml.jackson.databind.ObjectMapper;
9 import com.fasterxml.jackson.databind.cfg.MapperBuilder;
10 import com.fasterxml.jackson.databind.cfg.PackageVersion;
11 
12 /**
13  * JSON-format specific {@link ObjectMapper} implementation.
14  *
15  * @since 2.10
16  */
17 public class JsonMapper extends ObjectMapper
18 {
19     private static final long serialVersionUID = 1L;
20 
21     /**
22      * Base implementation for "Vanilla" {@link ObjectMapper}, used with
23      * JSON dataformat backend.
24      *
25      * @since 2.10
26      */
27     public static class Builder extends MapperBuilder<JsonMapper, Builder>
28     {
Builder(JsonMapper m)29         public Builder(JsonMapper m) {
30             super(m);
31         }
32 
enable(JsonReadFeature... features)33         public Builder enable(JsonReadFeature... features)  {
34             for (JsonReadFeature f : features) {
35                 _mapper.enable(f.mappedFeature());
36             }
37             return this;
38         }
39 
disable(JsonReadFeature... features)40         public Builder disable(JsonReadFeature... features) {
41             for (JsonReadFeature f : features) {
42                 _mapper.disable(f.mappedFeature());
43             }
44             return this;
45         }
46 
configure(JsonReadFeature f, boolean state)47         public Builder configure(JsonReadFeature f, boolean state)
48         {
49             if (state) {
50                 _mapper.enable(f.mappedFeature());
51             } else {
52                 _mapper.disable(f.mappedFeature());
53             }
54             return this;
55         }
56 
enable(JsonWriteFeature... features)57         public Builder enable(JsonWriteFeature... features)  {
58             for (JsonWriteFeature f : features) {
59                 _mapper.enable(f.mappedFeature());
60             }
61             return this;
62         }
63 
disable(JsonWriteFeature... features)64         public Builder disable(JsonWriteFeature... features) {
65             for (JsonWriteFeature f : features) {
66                 _mapper.disable(f.mappedFeature());
67             }
68             return this;
69         }
70 
configure(JsonWriteFeature f, boolean state)71         public Builder configure(JsonWriteFeature f, boolean state)
72         {
73             if (state) {
74                 _mapper.enable(f.mappedFeature());
75             } else {
76                 _mapper.disable(f.mappedFeature());
77             }
78             return this;
79         }
80     }
81 
82     /*
83     /**********************************************************
84     /* Life-cycle, constructors
85     /**********************************************************
86      */
87 
JsonMapper()88     public JsonMapper() {
89         this(new JsonFactory());
90     }
91 
JsonMapper(JsonFactory f)92     public JsonMapper(JsonFactory f) {
93         super(f);
94     }
95 
JsonMapper(JsonMapper src)96     protected JsonMapper(JsonMapper src) {
97         super(src);
98     }
99 
100     @Override
copy()101     public JsonMapper copy()
102     {
103         _checkInvalidCopy(JsonMapper.class);
104         return new JsonMapper(this);
105     }
106 
107     /*
108     /**********************************************************
109     /* Life-cycle, builders
110     /**********************************************************
111      */
112 
builder()113     public static JsonMapper.Builder builder() {
114         return new Builder(new JsonMapper());
115     }
116 
builder(JsonFactory streamFactory)117     public static Builder builder(JsonFactory streamFactory) {
118         return new Builder(new JsonMapper(streamFactory));
119     }
120 
rebuild()121     public JsonMapper.Builder  rebuild() {
122         // 09-Dec-2018, tatu: Not as good as what 3.0 has wrt immutability, but best approximation
123         //     we have for 2.x
124         return new Builder(this.copy());
125     }
126 
127     /*
128     /**********************************************************
129     /* Standard method overrides
130     /**********************************************************
131      */
132 
133     @Override
version()134     public Version version() {
135         return PackageVersion.VERSION;
136     }
137 
138     @Override
getFactory()139     public JsonFactory getFactory() {
140         return _jsonFactory;
141     }
142 
143     /*
144     /**********************************************************
145     /* JSON-specific accessors, mutators
146     /**********************************************************
147      */
148 
149     // // // 25-Oct-2018, tatu: Since for 2.x these will simply map to legacy settings,
150     // // //   we will fake them
151 
isEnabled(JsonReadFeature f)152     public boolean isEnabled(JsonReadFeature f) {
153         return isEnabled(f.mappedFeature());
154     }
155 
isEnabled(JsonWriteFeature f)156     public boolean isEnabled(JsonWriteFeature f) {
157         return isEnabled(f.mappedFeature());
158     }
159 }
160