/** * Method that will try to find a serializer, either from cache * or by constructing one; but will not return an "unknown" serializer * if this can not be done but rather returns null. * * @return Serializer if one can be found, null if not. */ protected JsonSerializer<Object> _findExplicitSerializer(Class<?> type) { // Fast lookup from local lookup thingy works? JsonSerializer<Object> ser = _knownSerializers.get(type); if (ser != null) { return ser; } // If not, maybe shared map already has it? ser = _serializerCache.findSerializer(type); if (ser != null) { return ser; } try { return _createAndCacheSerializer(type); } catch (Exception e) { return null; } }
@Override public JsonSerializer<Object> findValueSerializer(Class<?> type) throws JsonMappingException { // Fast lookup from local lookup thingy works? JsonSerializer<Object> ser = _knownSerializers.get(type); if (ser != null) { return ser; } // If not, maybe shared map already has it? ser = _serializerCache.findSerializer(type); if (ser != null) { return ser; } // If neither, must create ser = _createAndCacheSerializer(type); // Not found? Must use the unknown type serializer /* Couldn't create? Need to return the fallback serializer, which * most likely will report an error: but one question is whether * we should cache it? */ if (ser == null) { ser = getUnknownTypeSerializer(type); // Should this be added to lookups? if (CACHE_UNKNOWN_MAPPINGS) { _serializerCache.addSerializer(type, ser); } } return ser; }