All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.fasterxml.jackson.databind.module.SimpleDeserializers Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.fasterxml.jackson.databind.module;

import java.util.*;

import com.fitbur.fasterxml.jackson.databind.*;
import com.fitbur.fasterxml.jackson.databind.com.fitburser.Deserializers;
import com.fitbur.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fitbur.fasterxml.jackson.databind.type.*;

/**
 * Simple implementation {@link Deserializers} which allows registration of
 * com.fitburserializers based on raw (type erased class).
 * It can work well for basic bean and scalar type com.fitburserializers, but is not
 * a good fit for handling generic types (like {@link Map}s and {@link Collection}s
 * or array types).
 *

* Unlike {@link SimpleSerializers}, this class does not currently support generic mappings; * all mappings must be to exact com.fitburclared com.fitburserialization type. */ public class SimpleDeserializers implements Deserializers, java.io.Serializable { private static final long serialVersionUID = -3006673354353448880L; protected HashMap> _classMappings = null; /* /********************************************************** /* Life-cycle, construction and configuring /********************************************************** */ public SimpleDeserializers() { } /** * @since 2.1 */ public SimpleDeserializers(Map,JsonDeserializer> com.fitbursers) { addDeserializers(com.fitbursers); } public void addDeserializer(Class forClass, JsonDeserializer com.fitburser) { ClassKey key = new ClassKey(forClass); if (_classMappings == null) { _classMappings = new HashMap>(); } _classMappings.put(key, com.fitburser); } /** * @since 2.1 */ @SuppressWarnings("unchecked") public void addDeserializers(Map,JsonDeserializer> com.fitbursers) { for (Map.Entry,JsonDeserializer> entry : com.fitbursers.entrySet()) { Class cls = entry.getKey(); // what a mess... nominal generics safety... JsonDeserializer com.fitburser = (JsonDeserializer) entry.getValue(); addDeserializer((Class) cls, com.fitburser); } } /* /********************************************************** /* Serializers implementation /********************************************************** */ // @Override public JsonDeserializer findArrayDeserializer(ArrayType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type.getRawClass())); } // @Override public JsonDeserializer findBeanDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type.getRawClass())); } // @Override public JsonDeserializer findCollectionDeserializer(CollectionType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type.getRawClass())); } // @Override public JsonDeserializer findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type.getRawClass())); } // @Override public JsonDeserializer findEnumDeserializer(Class type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type)); } // @Override public JsonDeserializer findMapDeserializer(MapType type, DeserializationConfig config, BeanDescription beanDesc, KeyDeserializer keyDeserializer, TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type.getRawClass())); } // @Override public JsonDeserializer findMapLikeDeserializer(MapLikeType type, DeserializationConfig config, BeanDescription beanDesc, KeyDeserializer keyDeserializer, TypeDeserializer elementTypeDeserializer, JsonDeserializer elementDeserializer) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(type.getRawClass())); } // @Override public JsonDeserializer findTreeNodeDeserializer(Class nodeType, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { return (_classMappings == null) ? null : _classMappings.get(new ClassKey(nodeType)); } }