Merge branch '5.2.x'

# Conflicts:
#	spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java
#	spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java
This commit is contained in:
Juergen Hoeller
2020-05-22 17:16:09 +02:00
18 changed files with 80 additions and 74 deletions

View File

@@ -105,7 +105,7 @@ public final class ReactiveTypeDescriptor {
* Whether the underlying operation is deferred and needs to be started
* explicitly, e.g. via subscribing (or similar), or whether it is triggered
* without the consumer having any control.
* @since 5.1.16
* @since 5.2.7
*/
public boolean isDeferred() {
return this.deferred;
@@ -169,7 +169,7 @@ public final class ReactiveTypeDescriptor {
* non-deferred, async type such as {@link java.util.concurrent.CompletableFuture}.
* @param type the reactive type
* @param emptySupplier a supplier of an empty-value instance of the reactive type
* @since 5.1.16
* @since 5.2.7
*/
public static ReactiveTypeDescriptor nonDeferredAsyncValue(Class<?> type, Supplier<?> emptySupplier) {
return new ReactiveTypeDescriptor(type, false, false, emptySupplier, false);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.core.serializer;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -24,8 +25,10 @@ import java.io.InputStream;
*
* @author Gary Russell
* @author Mark Fisher
* @author Juergen Hoeller
* @since 3.0.5
* @param <T> the object type
* @see Serializer
*/
@FunctionalInterface
public interface Deserializer<T> {
@@ -41,4 +44,15 @@ public interface Deserializer<T> {
*/
T deserialize(InputStream inputStream) throws IOException;
/**
* Read (assemble) an object of type T from the given byte array.
* @param serialized the byte array
* @return the deserialized object
* @throws IOException in case of deserialization failure
* @since 5.2.7
*/
default T deserializeFromByteArray(byte[] serialized) throws IOException {
return deserialize(new ByteArrayInputStream(serialized));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.core.serializer;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -24,8 +25,10 @@ import java.io.OutputStream;
*
* @author Gary Russell
* @author Mark Fisher
* @author Juergen Hoeller
* @since 3.0.5
* @param <T> the object type
* @see Deserializer
*/
@FunctionalInterface
public interface Serializer<T> {
@@ -41,4 +44,17 @@ public interface Serializer<T> {
*/
void serialize(T object, OutputStream outputStream) throws IOException;
/**
* Turn an object of type T into a serialized byte array.
* @param object the object to serialize
* @return the resulting byte array
* @throws IOException in case of serialization failure
* @since 5.2.7
*/
default byte[] serializeToByteArray(T object) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
serialize(object, out);
return out.toByteArray();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package org.springframework.core.serializer.support;
import java.io.ByteArrayOutputStream;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.serializer.DefaultSerializer;
import org.springframework.core.serializer.Serializer;
@@ -58,10 +56,8 @@ public class SerializingConverter implements Converter<Object, byte[]> {
*/
@Override
public byte[] convert(Object source) {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024);
try {
this.serializer.serialize(source, byteStream);
return byteStream.toByteArray();
return this.serializer.serializeToByteArray(source);
}
catch (Throwable ex) {
throw new SerializationFailedException("Failed to serialize object using " +