/** * Constructor for creating master (or "blue-print") provider object, * which is only used as the template for constructing per-binding * instances. */ public StdSerializerProvider() { super(null); _serializerFactory = null; _serializerCache = new SerializerCache(); // Blueprints doesn't have access to any serializers... _knownSerializers = null; _rootNames = new RootNameLookup(); }
/** * @since 1.5 ] */ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<Object> ser; try { ser = _createUntypedSerializer(type, property); } catch (IllegalArgumentException iae) { /* We better only expose checked exceptions, since those * are what caller is expected to handle */ throw new JsonMappingException(iae.getMessage(), null, iae); } if (ser != null) { _serializerCache.addAndResolveNonTypedSerializer(type, ser, this); } return ser; }
@Override public JsonSerializer<Object> findTypedValueSerializer(JavaType valueType, boolean cache, BeanProperty property) throws JsonMappingException { // Two-phase lookups; local non-shared cache, then shared: JsonSerializer<Object> ser = _knownSerializers.typedValueSerializer(valueType); if (ser != null) { return ser; } // If not, maybe shared map already has it? ser = _serializerCache.typedValueSerializer(valueType); if (ser != null) { return ser; } // Well, let's just compose from pieces: ser = findValueSerializer(valueType, property); TypeSerializer typeSer = _serializerFactory.createTypeSerializer(_config, valueType, property); if (typeSer != null) { ser = new WrappedSerializer(typeSer, ser); } if (cache) { _serializerCache.addTypedSerializer(valueType, ser); } return ser; }
/** * 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> _findExplicitUntypedSerializer(Class<?> runtimeType, BeanProperty property) { // Fast lookup from local lookup thingy works? JsonSerializer<Object> ser = _knownSerializers.untypedValueSerializer(runtimeType); if (ser != null) { return ser; } // If not, maybe shared map already has it? ser = _serializerCache.untypedValueSerializer(runtimeType); if (ser != null) { return ser; } try { return _createAndCacheUntypedSerializer(runtimeType, property); } catch (Exception e) { return null; } }
@Override public int cachedSerializersCount() { return _serializerCache.size(); }
@Override public void flushCachedSerializers() { _serializerCache.flush(); }
/** * "Copy-constructor", used from {@link #createInstance} (or by * sub-classes) * * @param src Blueprint object used as the baseline for this instance */ protected StdSerializerProvider(SerializationConfig config, StdSerializerProvider src, SerializerFactory f) { super(config); if (config == null) { throw new NullPointerException(); } _serializerFactory = f; _serializerCache = src._serializerCache; _unknownTypeSerializer = src._unknownTypeSerializer; _keySerializer = src._keySerializer; _nullValueSerializer = src._nullValueSerializer; _nullKeySerializer = src._nullKeySerializer; _rootNames = src._rootNames; /* Non-blueprint instances do have a read-only map; one that doesn't * need synchronization for lookups. */ _knownSerializers = _serializerCache.getReadOnlyLookupMap(); }
if (ser == null) { ser = _serializerCache.untypedValueSerializer(valueType); if (ser == null) { ser = _serializerCache.untypedValueSerializer(_config.constructType(valueType)); if (ser == null) {
@Override public int cachedSerializersCount() { return _serializerCache.size(); }
@Override public void flushCachedSerializers() { _serializerCache.flush(); }
/** * "Copy-constructor", used from {@link #createInstance} (or by * sub-classes) * * @param src Blueprint object used as the baseline for this instance */ protected StdSerializerProvider(SerializationConfig config, StdSerializerProvider src, SerializerFactory f) { super(config); if (config == null) { throw new NullPointerException(); } _serializerFactory = f; _serializerCache = src._serializerCache; _unknownTypeSerializer = src._unknownTypeSerializer; _keySerializer = src._keySerializer; _nullValueSerializer = src._nullValueSerializer; _nullKeySerializer = src._nullKeySerializer; _rootNames = src._rootNames; /* Non-blueprint instances do have a read-only map; one that doesn't * need synchronization for lookups. */ _knownSerializers = _serializerCache.getReadOnlyLookupMap(); }
ser = _serializerCache.typedValueSerializer(valueType); if (ser != null) { return ser; _serializerCache.addTypedSerializer(valueType, ser);
if (ser == null) { ser = _serializerCache.untypedValueSerializer(valueType); if (ser == null) {
/** * Method that will try to construct a value serializer; and if * one is successfully created, cache it for reuse. */ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> type, BeanProperty property) throws JsonMappingException { JsonSerializer<Object> ser; try { ser = _createUntypedSerializer(_config.constructType(type), property); } catch (IllegalArgumentException iae) { /* We better only expose checked exceptions, since those * are what caller is expected to handle */ throw new JsonMappingException(iae.getMessage(), null, iae); } if (ser != null) { _serializerCache.addAndResolveNonTypedSerializer(type, ser, this); } return ser; }
@Override public int cachedSerializersCount() { return _serializerCache.size(); }
@Override public void flushCachedSerializers() { _serializerCache.flush(); }
/** * Constructor for creating master (or "blue-print") provider object, * which is only used as the template for constructing per-binding * instances. */ public StdSerializerProvider() { super(null); _serializerFactory = null; _serializerCache = new SerializerCache(); // Blueprints doesn't have access to any serializers... _knownSerializers = null; _rootNames = new RootNameLookup(); }
/** * "Copy-constructor", used from {@link #createInstance} (or by * sub-classes) * * @param src Blueprint object used as the baseline for this instance */ protected StdSerializerProvider(SerializationConfig config, StdSerializerProvider src, SerializerFactory f) { super(config); if (config == null) { throw new NullPointerException(); } _serializerFactory = f; _serializerCache = src._serializerCache; _unknownTypeSerializer = src._unknownTypeSerializer; _keySerializer = src._keySerializer; _nullValueSerializer = src._nullValueSerializer; _nullKeySerializer = src._nullKeySerializer; _rootNames = src._rootNames; /* Non-blueprint instances do have a read-only map; one that doesn't * need synchronization for lookups. */ _knownSerializers = _serializerCache.getReadOnlyLookupMap(); }
@Override public JsonSerializer<Object> findTypedValueSerializer(JavaType valueType, boolean cache, BeanProperty property) throws JsonMappingException { // Two-phase lookups; local non-shared cache, then shared: JsonSerializer<Object> ser = _knownSerializers.typedValueSerializer(valueType); if (ser != null) { return ser; } // If not, maybe shared map already has it? ser = _serializerCache.typedValueSerializer(valueType); if (ser != null) { return ser; } // Well, let's just compose from pieces: ser = findValueSerializer(valueType, property); TypeSerializer typeSer = _serializerFactory.createTypeSerializer(_config, valueType, property); if (typeSer != null) { ser = new WrappedSerializer(typeSer, ser); } if (cache) { _serializerCache.addTypedSerializer(valueType, ser); } return ser; }
/** * 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> _findExplicitUntypedSerializer(Class<?> runtimeType, BeanProperty property) { // Fast lookup from local lookup thingy works? JsonSerializer<Object> ser = _knownSerializers.untypedValueSerializer(runtimeType); if (ser != null) { return ser; } // If not, maybe shared map already has it? ser = _serializerCache.untypedValueSerializer(runtimeType); if (ser != null) { return ser; } try { return _createAndCacheUntypedSerializer(runtimeType, property); } catch (Exception e) { return null; } }