throws JsonMappingException JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); final DeserializationConfig config = ctxt.getConfig();
provider.findNullKeySerializer(_type.getKeyType(), _property) .serialize(null, gen, provider); } else {
/** * We need to use this method to properly handle possible contextual variants of key and value * deserializers, as well as type deserializers. */ @Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { KeyDeserializer kd = keyDeserializer; if (kd == null) { kd = ctxt.findKeyDeserializer(type.getKeyType(), property); } JsonDeserializer<?> valueDeser = elementDeserializer; final JavaType vt = type.getContentType(); if (valueDeser == null) { valueDeser = ctxt.findContextualValueDeserializer(vt, property); } else { // if directly assigned, probably not yet contextual, so: valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt); } // Type deserializer is slightly different; must be passed, but needs to become contextual: TypeDeserializer vtd = elementTypeDeserializer; if (vtd != null) { vtd = vtd.forProperty(property); } return _createContextual(type, kd, vtd, valueDeser, creatorMethod, findContentNullProvider(ctxt, property, valueDeser)); }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { JsonMapFormatVisitor v2 = (visitor == null) ? null : visitor.expectMapFormat(typeHint); if (v2 != null) { v2.keyFormat(_keySerializer, _type.getKeyType()); JsonSerializer<?> valueSer = _valueSerializer; final JavaType vt = _type.getContentType(); final SerializerProvider prov = visitor.getProvider(); if (valueSer == null) { valueSer = _findAndAddDynamic(_dynamicValueSerializers, vt, prov); } final JsonSerializer<?> valueSer2 = valueSer; v2.valueFormat(new JsonFormatVisitable() { final JavaType arrayType = prov.getTypeFactory().constructArrayType(vt); @Override public void acceptJsonFormatVisitor( JsonFormatVisitorWrapper v3, JavaType hint3) throws JsonMappingException { JsonArrayFormatVisitor v4 = v3.expectArrayFormat(arrayType); if (v4 != null) { v4.itemsFormat(valueSer2, vt); } } }, vt); } }
keySer = provider.findKeySerializer(_type.getKeyType(), property); } else { keySer = provider.handleSecondaryContextualization(keySer, property);
@SuppressWarnings("unchecked") @Override public void resolve(DeserializationContext ctxt) throws JsonMappingException { JavaType keyType = javaType.getKeyType(); if (keyType.getRawClass().isAssignableFrom(Comparable.class)) { keyComparator = (Comparator<Object> & Serializable) (o1, o2) -> ((Comparable) o1).compareTo(o2); } else { keyComparator = (Comparator<Object> & Serializable) (o1, o2) -> o1.toString().compareTo(o2.toString()); } keyDeserializer = ctxt.findKeyDeserializer(keyType, null); valueDeserializer = ctxt.findRootValueDeserializer(javaType.getContentType()); } }
@Override JavaType emulatedJavaType(JavaType type, TypeFactory typeFactory) { MapLikeType mapLikeType = (MapLikeType) type; return typeFactory.constructMapType(LinkedHashMap.class, mapLikeType.getKeyType(), mapLikeType.getContentType()); }
@Override public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) { if (type.isTypeOrSubTypeOf(EMap.class)) { if (type.getKeyType().isTypeOrSubTypeOf(String.class)) { return _mapSerializer; } } return super.findMapLikeSerializer(config, type, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer); }
@Override public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) { if (type.isTypeOrSubTypeOf(EMap.class)) { if (type.getKeyType().isTypeOrSubTypeOf(String.class)) { return _mapSerializer; } } return super.findMapLikeSerializer(config, type, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer); }
public static String createSignature(MapLikeType mapLikeType) { return "map<" + createSignature(mapLikeType.getKeyType()) + "," + createSignature(mapLikeType.getContentType()) + ">"; } }
provider.findNullKeySerializer(_type.getKeyType(), _property) .serialize(null, gen, provider); } else {
/** * Same as {@link #getType(com.fasterxml.jackson.databind.type.SimpleType)} * * @param jacksonType * @return */ public Type getType(MapLikeType jacksonType) { String signature = JacksonSignature.createSignature(jacksonType); JavaType keyType = jacksonType.getKeyType(); JavaType valueType = jacksonType.getContentType(); Class<?> containerClass = jacksonType.getRawClass(); String keySignature = JacksonSignature.createSignature(keyType); String valSignature = JacksonSignature.createSignature(valueType); MapTypeJrapidoc type = new MapTypeJrapidoc(containerClass.getName(), signature, keyType.getRawClass().getName(), keySignature, valueType .getRawClass().getName(), valSignature); if (cache.containsKey(signature)) { return cache.get(signature); } cache.put(signature, type); getType(keyType); getType(valueType); return type; }
/** * We need to use this method to properly handle possible contextual variants of key and value * deserializers, as well as type deserializers. */ @Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { KeyDeserializer kd = keyDeserializer; if (kd == null) { kd = ctxt.findKeyDeserializer(type.getKeyType(), property); } JsonDeserializer<?> ed = elementDeserializer; if (ed == null) { ed = ctxt.findContextualValueDeserializer(type.getContentType(), property); } // Type deserializer is slightly different; must be passed, but needs to become contextual: TypeDeserializer etd = elementTypeDeserializer; if (etd != null && property != null) { etd = etd.forProperty(property); } return (_createContextual(type, kd, etd, ed, creatorMethod)); }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { JsonMapFormatVisitor v2 = (visitor == null) ? null : visitor.expectMapFormat(typeHint); if (v2 != null) { v2.keyFormat(_keySerializer, _type.getKeyType()); JsonSerializer<?> valueSer = _valueSerializer; JavaType vt = _type.getContentType(); if (valueSer == null) { valueSer = _findAndAddDynamic(_dynamicValueSerializers, vt, visitor.getProvider()); } v2.valueFormat(valueSer, vt); } }
@Override public JsonDeserializer<?> createMapLikeDeserializer(DeserializationContext ctxt, MapLikeType type, final BeanDescription beanDesc) throws JsonMappingException { JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); // First: is there annotation-specified deserializer for values? @SuppressWarnings("unchecked") JsonDeserializer<Object> contentDeser = (JsonDeserializer<Object>) contentType.getValueHandler(); // Ok: need a key deserializer (null indicates 'default' here) KeyDeserializer keyDes = (KeyDeserializer) keyType.getValueHandler(); /* !!! 24-Jan-2012, tatu: NOTE: impls MUST use resolve() to find key deserializer! if (keyDes == null) { keyDes = p.findKeyDeserializer(config, keyType, property); } */ // Then optional type info (1.5); either attached to type, or resolve separately: TypeDeserializer contentTypeDeser = contentType.getTypeHandler(); // but if not, may still be possible to find: if (contentTypeDeser == null) { contentTypeDeser = findTypeDeserializer(ctxt.getConfig(), contentType); } return _findCustomMapLikeDeserializer(type, ctxt.getConfig(), beanDesc, keyDes, contentTypeDeser, contentDeser); }
@Override public JsonDeserializer<?> createMapLikeDeserializer(DeserializationContext ctxt, MapLikeType type, final BeanDescription beanDesc) throws JsonMappingException { JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); // First: is there annotation-specified deserializer for values? @SuppressWarnings("unchecked") JsonDeserializer<Object> contentDeser = (JsonDeserializer<Object>) contentType.getValueHandler(); // Ok: need a key deserializer (null indicates 'default' here) KeyDeserializer keyDes = (KeyDeserializer) keyType.getValueHandler(); /* !!! 24-Jan-2012, tatu: NOTE: impls MUST use resolve() to find key deserializer! if (keyDes == null) { keyDes = p.findKeyDeserializer(config, keyType, property); } */ // Then optional type info (1.5); either attached to type, or resolve separately: TypeDeserializer contentTypeDeser = contentType.getTypeHandler(); // but if not, may still be possible to find: if (contentTypeDeser == null) { contentTypeDeser = findTypeDeserializer(ctxt.getConfig(), contentType); } return _findCustomMapLikeDeserializer(type, ctxt.getConfig(), beanDesc, keyDes, contentTypeDeser, contentDeser); }
throws JsonMappingException JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); final DeserializationConfig config = ctxt.getConfig();
throws JsonMappingException JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); final DeserializationConfig config = ctxt.getConfig();
throws JsonMappingException JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); final DeserializationConfig config = ctxt.getConfig();
throws JsonMappingException JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); final DeserializationConfig config = ctxt.getConfig();