View Javadoc
1   package com.buckosoft.PicMan.service.support;
2   
3   import com.fasterxml.jackson.databind.BeanDescription;
4   import com.fasterxml.jackson.databind.DeserializationConfig;
5   import com.fasterxml.jackson.databind.JsonDeserializer;
6   import com.fasterxml.jackson.databind.JsonMappingException;
7   import com.fasterxml.jackson.databind.KeyDeserializer;
8   import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
9   import com.fasterxml.jackson.databind.module.SimpleDeserializers;
10  import com.fasterxml.jackson.databind.type.MapLikeType;
11  import com.fasterxml.jackson.databind.type.MapType;
12  //import com.fasterxml.jackson.databind.deser.DeserializationFallbacksProvider;
13  
14  public class MapDeserializersExt extends SimpleDeserializers {
15  
16  	private static final long serialVersionUID = 1L;
17  
18  	@Override
19  	public JsonDeserializer<?> findMapDeserializer(MapType type,
20  			DeserializationConfig config, BeanDescription beanDesc,
21  			KeyDeserializer keyDeserializer,
22  			TypeDeserializer elementTypeDeserializer,
23  			JsonDeserializer<?> elementDeserializer)
24  			throws JsonMappingException {
25  		return createMapDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer);
26  	}
27  
28  	@Override
29  	public JsonDeserializer<?> findMapLikeDeserializer(MapLikeType type,
30  			DeserializationConfig config, BeanDescription beanDesc,
31  			KeyDeserializer keyDeserializer,
32  			TypeDeserializer elementTypeDeserializer,
33  			JsonDeserializer<?> elementDeserializer)
34  			throws JsonMappingException {
35  		return createMapDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer);
36  	}
37  
38  	@SuppressWarnings("unchecked")
39  	public JsonDeserializer<?> createMapDeserializer(MapLikeType type,
40  			DeserializationConfig config, BeanDescription beanDesc,
41  			KeyDeserializer keyDeserializer,
42  			TypeDeserializer elementTypeDeserializer,
43  			JsonDeserializer<?> elementDeserializer) {
44  /*
45          if (type.isInterface() || type.isAbstract()) {
46              @SuppressWarnings("rawtypes")
47              Class<? extends Map> fallback = DeserializationFallbacksProvider.getMapFallbacks().get(beanDesc.getClassInfo().getRawType().getName());
48              if (fallback == null) {
49                  throw new IllegalArgumentException("Can not find a deserializer for non-concrete Map type "+type);
50              }
51  
52              type = (MapType) config.constructSpecializedType(type, fallback);
53              // But if so, also need to re-check creators...
54              beanDesc = config.introspectForCreation(type);
55          }
56  */	
57  		//BeanDescription keyDesc = config.introspectClassAnnotations(type.getKeyType());
58  		return new KeyValueMapDeserializer(type, null, null, (JsonDeserializer<Object>) elementDeserializer, elementTypeDeserializer);
59  	}
60  }