Construct StringWriter instances with appropriate initial size
Closes gh-25789
(cherry picked from commit 9dfef59af2)
This commit is contained in:
@@ -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.
|
||||
@@ -211,9 +211,11 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||
JavaType javaType = getJavaType(targetClass, conversionHint);
|
||||
Object payload = message.getPayload();
|
||||
Class<?> view = getSerializationView(conversionHint);
|
||||
// Note: in the view case, calling withType instead of forType for compatibility with Jackson <2.5
|
||||
try {
|
||||
if (payload instanceof byte[]) {
|
||||
if (targetClass.isInstance(payload)) {
|
||||
return payload;
|
||||
}
|
||||
else if (payload instanceof byte[]) {
|
||||
if (view != null) {
|
||||
return this.objectMapper.readerWithView(view).forType(javaType).readValue((byte[]) payload);
|
||||
}
|
||||
@@ -222,6 +224,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Assuming a text-based source payload
|
||||
if (view != null) {
|
||||
return this.objectMapper.readerWithView(view).forType(javaType).readValue(payload.toString());
|
||||
}
|
||||
@@ -270,7 +273,8 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||
payload = out.toByteArray();
|
||||
}
|
||||
else {
|
||||
Writer writer = new StringWriter();
|
||||
// Assuming a text-based target payload
|
||||
Writer writer = new StringWriter(1024);
|
||||
if (view != null) {
|
||||
this.objectMapper.writerWithView(view).writeValue(writer, payload);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -173,13 +173,13 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
|
||||
Assert.notNull(this.marshaller, "Property 'marshaller' is required");
|
||||
try {
|
||||
if (byte[].class == getSerializedPayloadClass()) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
||||
Result result = new StreamResult(out);
|
||||
this.marshaller.marshal(payload, result);
|
||||
payload = out.toByteArray();
|
||||
}
|
||||
else {
|
||||
Writer writer = new StringWriter();
|
||||
Writer writer = new StringWriter(1024);
|
||||
Result result = new StreamResult(writer);
|
||||
this.marshaller.marshal(payload, result);
|
||||
payload = writer.toString();
|
||||
|
||||
Reference in New Issue
Block a user