@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls, ClassKey key) { for (Class<?> iface : cls.getInterfaces()) { key.reset(iface); JsonSerializer<?> ser = _interfaceMappings.get(key); if (ser != null) { return ser; } // [JACKSON-373] need to also check super-interfaces ser = _findInterfaceMapping(iface, key); if (ser != null) { return ser; } } return null; } }
@Override @SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<?> ser = findCustomSerializer(type.getRawClass(), config); if (ser != null) { return (JsonSerializer<Object>) ser; } return super.createSerializer(config, type, property); }
public class CustomObjectMapper extends ObjectMapper { public CustomObjectMapper() { CustomSerializerFactory sf = new CustomSerializerFactory(); sf.addSpecificMapping(ObjectId.class, new ObjectIdSerializer()); this.setSerializerFactory(sf); } }
/** * Associates all maps with our custom serialization mechanism, which will transform them into arrays of arrays * @see MapAsArraySerializer * @return */ @Produces public SerializerFactory createSerializerFactory() { CustomSerializerFactory customized = new CustomSerializerFactory(); customized.addGenericMapping(Map.class, new MapAsArraySerializer()); return customized; } public @Produces ObjectMapper createMapper() { ObjectMapper jsonMapper = new ObjectMapper(); // .... // now configure serializer jsonMapper.setSerializerFactory(createSerializerFactory()); // .... return jsonMapper; }
public void afterPropertiesSet() throws Exception { Assert.notNull(conversionService, "Must specify a valid ConversionService."); List<HttpMessageConverter<?>> converters = getRestTemplate().getMessageConverters(); ObjectMapper mapper = new ObjectMapper(); CustomSerializerFactory fac = new CustomSerializerFactory(); if (groovyPresent) { // Native conversion for Groovy GString objects fac.addSpecificMapping(GStringImpl.class, ToStringSerializer.instance); } mapper.setSerializerFactory(fac); for (HttpMessageConverter converter : converters) { if (converter instanceof MappingJacksonHttpMessageConverter) { ((MappingJacksonHttpMessageConverter) converter).setObjectMapper( mapper); } } }
XmlJavaTypeAdapters adapters = pkg.getAnnotation(XmlJavaTypeAdapters.class); if (adapters != null) { CustomSerializerFactory serializerFactory = new CustomSerializerFactory(); BeanDeserializerFactory deserializerFactory = new BeanDeserializerFactory(null); for (XmlJavaTypeAdapter a : adapters.value()) { deserializers.addDeserializer(a.type(), deserializer); deserializerFactory.withAdditionalDeserializers(deserializers); serializerFactory.addGenericMapping(a.type(), serializer); StdDeserializerProvider deserializerProvider = new StdDeserializerProvider(deserializerFactory);
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
ser = _findInterfaceMapping(curr, key); if (ser != null) { return ser;
@Override @SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<?> ser = findCustomSerializer(type.getRawClass(), config); if (ser != null) { return (JsonSerializer<Object>) ser; } return super.createSerializer(config, type, property); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls, ClassKey key) { for (Class<?> iface : cls.getInterfaces()) { key.reset(iface); JsonSerializer<?> ser = _interfaceMappings.get(key); if (ser != null) { return ser; } // [JACKSON-373] need to also check super-interfaces ser = _findInterfaceMapping(iface, key); if (ser != null) { return ser; } } return null; } }
@Override @SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<?> ser = findCustomSerializer(type.getRawClass(), config); if (ser != null) { return (JsonSerializer<Object>) ser; } return super.createSerializer(config, type, property); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
ser = _findInterfaceMapping(curr, key); if (ser != null) { return ser;
@Override @SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<?> ser = findCustomSerializer(type.getRawClass(), config); if (ser != null) { return (JsonSerializer<Object>) ser; } return super.createSerializer(config, type, property); }
@Override public SerializerFactory withConfig(Config config) { /* 22-Nov-2010, tatu: As with BeanSerializerFactory, must ensure type won't change * with this method, so: */ if (getClass() != CustomSerializerFactory.class) { throw new IllegalStateException("Subtype of CustomSerializerFactory ("+getClass().getName() +") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " +"additional serializer definitions"); } return new CustomSerializerFactory(config); }
protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls, ClassKey key) { for (Class<?> iface : cls.getInterfaces()) { key.reset(iface); JsonSerializer<?> ser = _interfaceMappings.get(key); if (ser != null) { return ser; } // [JACKSON-373] need to also check super-interfaces ser = _findInterfaceMapping(iface, key); if (ser != null) { return ser; } } return null; } }
@Override @SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException { JsonSerializer<?> ser = findCustomSerializer(type.getRawClass(), config); if (ser != null) { return (JsonSerializer<Object>) ser; } return super.createSerializer(config, type, property); }
protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls, ClassKey key) { for (Class<?> iface : cls.getInterfaces()) { key.reset(iface); JsonSerializer<?> ser = _interfaceMappings.get(key); if (ser != null) { return ser; } // [JACKSON-373] need to also check super-interfaces ser = _findInterfaceMapping(iface, key); if (ser != null) { return ser; } } return null; } }