Ok, thanks for the explanation. You're correct that in 2.7 the input and output maps are actually the same.
The short-circuit explanation also explains some other smaller differences we are seeing. We can just work around this for our case by either converting the contents of the map individually, or if we have to, forcing it through serialized json explcictly. We were actually just using this as a shortcut to force the conversion through json and back to cause the custom serialization logic to fire. Thanks. -gregj On Wednesday, August 17, 2016 at 4:59:15 PM UTC-7, Tatu Saloranta wrote: > > Semantics of `convertValue()` are bit vague, and I think what is happening > here is that code in 2.7 notices that incoming type is already same as > outgoing (that is, a `Map` is being given, and `Map` is expected -- hence > code considers it a no-operation and just returns input value. The intent > would be to allow simpler usage by user to do optional conversion, so from > multiple input types -- including already converted case -- without > user-side checks. > However that does prevent forced conversions where you really do want > serialization-into-token-buffer, deserialization-from-token-buffer into > target type. > > You should be able to verify that this is what is happening by just > checking that result is the same Map as input. > > One thing that is surprising is that I thought this short-circuit check > already existed prior to 2.6, so I didn't think that'd cause change for > this particular upgrade. > > -+ Tatu +- > > > On Wed, Aug 17, 2016 at 4:49 PM, Greg J <[email protected] > <javascript:>> wrote: > >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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.
