Hi --
We're trying to upgrade to Jackson 2.7 from 2.6 but are noticing some
unexpectedly different behavior in the way that custom serializers for
types are (or the case of 2.7, are not) being invoked when those types are
present as values in maps.
I didn't see anything in obvious the 2.7 release notes to indicate anything
like this, but thought I'd ask. Maybe we were getting lucky before on
something we shouldn't have been. So wondering if we're doing things right
or not. If we are I'll make a github issue.
An example of the different behavior we're seeing is in the below test,
which passes on 2.6.4, but doesn't on 2.7.5 -- the custom serializer
doesn't seem to be getting invoked on 2.7.5.
Thanks.
-gregj
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class MapConversionTest {
@Test
public void testConvertStringsInMaps() {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new
SimpleModule("ToUpperStringSerializerModule");
module.addSerializer(String.class, new ToUpperStringSerializer());
mapper.registerModule(module);
Map<String, String> map = new HashMap<>();
map.put("hello", "world");
Map<String, Object> converted = mapper.convertValue(map, Map.class);
assertEquals(map.get("hello").toUpperCase(),
converted.get("hello"));
}
static class ToUpperStringSerializer extends StdSerializer<String> {
private ToUpperStringSerializer() {
super(String.class);
}
@Override
public Class<String> handledType() {
return String.class;
}
@Override
public void serialize(String value, JsonGenerator gen,
SerializerProvider serializers)
throws JsonProcessingException, IOException
{
if(value == null) {
gen.writeNull();
} else {
gen.writeString(value.toUpperCase());
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.