View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package com.addthis.codec.jackson;
15  
16  import com.fasterxml.jackson.databind.BeanDescription;
17  import com.fasterxml.jackson.databind.DeserializationConfig;
18  import com.fasterxml.jackson.databind.JsonDeserializer;
19  import com.fasterxml.jackson.databind.JsonMappingException;
20  import com.fasterxml.jackson.databind.deser.Deserializers;
21  import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
22  import com.fasterxml.jackson.databind.type.ArrayType;
23  
24  public class CodecDeserializers extends Deserializers.Base {
25  
26      @Override
27      public JsonDeserializer<?> findArrayDeserializer(ArrayType type,
28                                                       DeserializationConfig config,
29                                                       BeanDescription beanDesc,
30                                                       TypeDeserializer elementTypeDeserializer,
31                                                       JsonDeserializer<?> elementDeserializer)
32              throws JsonMappingException {
33          // skip primitive and string cases that wouldn't become ObjectArrayDeserializers
34          if (elementDeserializer == null) {
35              Class<?> raw = type.getContentType().getRawClass();
36              if (type.getContentType().isPrimitive()) {
37                  return null;
38              } else if (raw == String.class) {
39                  return null;
40              }
41          }
42          return new IndexReportingObjectArrayDeserializer(type,
43                                                           (JsonDeserializer<Object>) elementDeserializer,
44                                                           elementTypeDeserializer);
45      }
46  }