Polish Jackson 3 support

- Improve Javadoc.

- Suppress warnings for "removal".

- Update copyright headers.

- Migrate several tests from:
  - MappingJackson2MessageConverter to JacksonJsonMessageConverter
  - Jackson2JsonEncoder to JacksonJsonEncoder
  - Jackson2JsonDecoder to JacksonJsonDecoder
  - Jackson2SmileEncoder to JacksonSmileEncoder
  - Jackson2ObjectMapperBuilder to JsonMapper and XmlMapper
  - MappingJackson2JsonView to JacksonJsonView
  - MappingJackson2HttpMessageConverter to JacksonJsonHttpMessageConverter
  - MappingJackson2XmlHttpMessageConverter to JacksonXmlHttpMessageConverter
This commit is contained in:
Sam Brannen
2025-05-14 16:55:27 +02:00
parent ea340fbe69
commit 01fea5e7ed
88 changed files with 402 additions and 346 deletions

View File

@@ -31,8 +31,9 @@ import org.springframework.http.codec.AbstractJacksonDecoder;
import org.springframework.util.MimeType;
/**
* Decode bytes into CBOR and convert to Object's with Jackson 3.x.
* Stream decoding is not supported yet.
* Decode bytes into CBOR and convert to Objects with Jackson 3.x.
*
* <p>Stream decoding is currently not supported.
*
* @author Sebastien Deleuze
* @since 7.0
@@ -70,7 +71,8 @@ public class JacksonCborDecoder extends AbstractJacksonDecoder {
@Override
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType,
@Nullable Map<String, Object> hints) {
throw new UnsupportedOperationException("Does not support stream decoding yet");
throw new UnsupportedOperationException("Stream decoding is currently not supported");
}
}

View File

@@ -33,7 +33,8 @@ import org.springframework.util.MimeType;
/**
* Encode from an {@code Object} to bytes of CBOR objects using Jackson 3.x.
* Stream encoding is not supported yet.
*
* <p>Stream encoding is currently not supported.
*
* @author Sebastien Deleuze
* @since 7.0
@@ -73,7 +74,8 @@ public class JacksonCborEncoder extends AbstractJacksonEncoder {
@Override
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
throw new UnsupportedOperationException("Does not support stream encoding yet");
throw new UnsupportedOperationException("Stream encoding is currently not supported");
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.http.codec.AbstractJacksonDecoder;
import org.springframework.util.MimeType;
/**
* Decode a byte stream into Smile and convert to Object's with Jackson 3.x,
* Decode a byte stream into Smile and convert to Objects with Jackson 3.x,
* leveraging non-blocking parsing.
*
* <p>The default constructor loads {@link tools.jackson.databind.JacksonModule}s
@@ -39,6 +39,7 @@ public class JacksonSmileDecoder extends AbstractJacksonDecoder {
new MimeType("application", "x-jackson-smile"),
new MimeType("application", "*+x-jackson-smile")};
/**
* Construct a new instance with a {@link SmileMapper} customized with the
* {@link tools.jackson.databind.JacksonModule}s found by

View File

@@ -30,8 +30,9 @@ import org.springframework.util.MimeType;
/**
* Encode from an {@code Object} stream to a byte stream of Smile objects using Jackson 3.x.
* For non-streaming use cases, {@link Flux} elements are collected into a {@link List}
* before serialization for performance reason.
*
* <p>For non-streaming use cases, {@link Flux} elements are collected into a {@link List}
* before serialization for performance reasons.
*
* <p>The default constructor loads {@link tools.jackson.databind.JacksonModule}s
* found by {@link MapperBuilder#findModules(ClassLoader)}.
@@ -98,4 +99,5 @@ public class JacksonSmileEncoder extends AbstractJacksonEncoder {
}
return null;
}
}

View File

@@ -111,7 +111,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
/**
* Construct a new instance with a provided {@link MapperBuilder builder}
* Construct a new instance with the provided {@link MapperBuilder builder}
* customized with the {@link tools.jackson.databind.JacksonModule}s found
* by {@link MapperBuilder#findModules(ClassLoader)}.
*/
@@ -141,7 +141,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
}
/**
* Construct a new instance with a provided {@link ObjectMapper}.
* Construct a new instance with the provided {@link ObjectMapper}.
*/
protected AbstractJacksonHttpMessageConverter(ObjectMapper objectMapper) {
this.defaultObjectMapper = objectMapper;
@@ -367,10 +367,10 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
}
/**
* Subclasses can use this method to customize {@link ObjectReader} used
* Subclasses can use this method to customize the {@link ObjectReader} used
* for reading values.
* @param reader the reader instance to customize
* @param javaType the target type of element values to read to
* @param javaType the type of element values to read
* @return the customized {@link ObjectReader}
*/
protected ObjectReader customizeReader(ObjectReader reader, JavaType javaType) {
@@ -380,7 +380,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
/**
* Determine the charset to use for JSON input.
* <p>By default this is either the charset from the input {@code MediaType}
* or otherwise falling back on {@code UTF-8}. Can be overridden in subclasses.
* or otherwise {@code UTF-8}. Can be overridden in subclasses.
* @param contentType the content type of the HTTP input message
* @return the charset to use
*/
@@ -448,7 +448,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
}
/**
* Subclasses can use this method to customize {@link ObjectWriter} used
* Subclasses can use this method to customize the {@link ObjectWriter} used
* for writing values.
* @param writer the writer instance to customize
* @param javaType the type of element values to write
@@ -464,7 +464,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
/**
* Write a prefix before the main content.
* @param generator the generator to use for writing content.
* @param object the object to write to the output message.
* @param object the object to write to the output message
*/
protected void writePrefix(JsonGenerator generator, Object object) {
}
@@ -472,7 +472,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
/**
* Write a suffix after the main content.
* @param generator the generator to use for writing content.
* @param object the object to write to the output message.
* @param object the object to write to the output message
*/
protected void writeSuffix(JsonGenerator generator, Object object) {
}
@@ -508,4 +508,5 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
protected boolean supportsRepeatableWrites(Object o) {
return true;
}
}

View File

@@ -65,7 +65,7 @@ public class JacksonXmlHttpMessageConverter extends AbstractJacksonHttpMessageCo
};
/**
* Construct a new instance with a {@link XmlMapper} created from
* Construct a new instance with an {@link XmlMapper} created from
* {@link #defensiveXmlFactory} and customized with the
* {@link tools.jackson.databind.JacksonModule}s found by
* {@link MapperBuilder#findModules(ClassLoader)} and

View File

@@ -35,21 +35,21 @@ import tools.jackson.databind.ser.VirtualBeanPropertyWriter;
import tools.jackson.databind.util.Converter;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;
/**
* Allows for creating Jackson 3.x ({@link ValueSerializer}, {@link ValueDeserializer},
* {@link KeyDeserializer}, {@link TypeResolverBuilder}, {@link TypeIdResolver})
* beans with autowiring against a Spring {@link ApplicationContext}.
* {@link KeyDeserializer}, {@link TypeResolverBuilder}, and {@link TypeIdResolver})
* beans with autowiring against a Spring {@code ApplicationContext}.
*
* <p>Also overrides all factory methods in {@link HandlerInstantiator},
* including non-abstract ones for {@link ValueInstantiator}, {@link ObjectIdGenerator}, {@link ObjectIdResolver},
* {@link PropertyNamingStrategy}, {@link Converter}, {@link VirtualBeanPropertyWriter}.
* including non-abstract methods for {@link ValueInstantiator}, {@link ObjectIdGenerator},
* {@link ObjectIdResolver}, {@link PropertyNamingStrategy}, {@link Converter}, and
* {@link VirtualBeanPropertyWriter}.
*
* @author Sebastien Deleuze
* @since 7.0
* @see ApplicationContext#getAutowireCapableBeanFactory()
* @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
* @see tools.jackson.databind.cfg.HandlerInstantiator
*/
public class JacksonHandlerInstantiator extends HandlerInstantiator {
@@ -58,7 +58,7 @@ public class JacksonHandlerInstantiator extends HandlerInstantiator {
/**
* Create a new AutowiredHandlerInstantiator for the given BeanFactory.
* Create a new {@code JacksonHandlerInstantiator} for the given BeanFactory.
* @param beanFactory the target BeanFactory
*/
public JacksonHandlerInstantiator(AutowireCapableBeanFactory beanFactory) {
@@ -66,6 +66,7 @@ public class JacksonHandlerInstantiator extends HandlerInstantiator {
this.beanFactory = beanFactory;
}
@Override
@Nullable
public ValueDeserializer<?> deserializerInstance(DeserializationConfig config, Annotated annotated, Class<?> deserClass) {
@@ -94,25 +95,21 @@ public class JacksonHandlerInstantiator extends HandlerInstantiator {
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
@Override
public ObjectIdGenerator<?> objectIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
return (ObjectIdGenerator<?>) this.beanFactory.createBean(implClass);
}
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
return (ObjectIdResolver) this.beanFactory.createBean(implClass);
}
@Override
public PropertyNamingStrategy namingStrategyInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
return (PropertyNamingStrategy) this.beanFactory.createBean(implClass);
}