-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple calls to ObjectMapper#canSerialize(Object.class) returns different values. #703
Comments
Reproduced here (and heavily affected), in 2.5.0. |
In SerializerProvider: protected JsonSerializer<Object> _findExplicitUntypedSerializer(Class<?> runtimeType)
throws JsonMappingException
{
// Fast lookup from local lookup thingy works?
JsonSerializer<Object> ser = _knownSerializers.untypedValueSerializer(runtimeType);
if (ser == null) {
// If not, maybe shared map already has it?
ser = _serializerCache.untypedValueSerializer(runtimeType);
if (ser == null) {
ser = _createAndCacheUntypedSerializer(runtimeType);
/* 18-Sep-2014, tatu: This is unfortunate patch over related change
* that pushes creation of "unknown type" serializer deeper down
* in BeanSerializerFactory; as a result, we need to "undo" creation
* here.
*/
if (isUnknownTypeSerializer(ser)) {
return null;
}
}
}
return ser;
} In first execution of: JsonSerializer<Object> ser = _knownSerializers.untypedValueSerializer(runtimeType);
I don't know if this is expected or not... but, if this is OK, it could be quickly fixed by moving this: if (isUnknownTypeSerializer(ser)) {
return null;
} out of the first if() clause. |
Proposed fix in #704 |
@flozano Thank you once again for the fix: I added a test and backported in 2.5 branch (to be included in 2.5.2) |
np, thanks for making jackson! |
In 2.5.1, the first call to
ObjectMapper#canSerialize(Object.class)
returns false.However, it returns true from the second call.
It seems to be cause by cache mechanism in
SerializerProvider
class.Sample code:
output:
The text was updated successfully, but these errors were encountered: