Avoid String allocations with Assert.state()
This commit is contained in:
parent
2a853aea67
commit
deabd66939
|
|
@ -356,7 +356,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||||
Charset charset = getCharset(contentType);
|
Charset charset = getCharset(contentType);
|
||||||
|
|
||||||
ObjectMapper objectMapper = selectObjectMapper(javaType.getRawClass(), contentType);
|
ObjectMapper objectMapper = selectObjectMapper(javaType.getRawClass(), contentType);
|
||||||
Assert.state(objectMapper != null, "No ObjectMapper for " + javaType);
|
Assert.state(objectMapper != null, () -> "No ObjectMapper for " + javaType);
|
||||||
|
|
||||||
boolean isUnicode = ENCODINGS.containsKey(charset.name()) ||
|
boolean isUnicode = ENCODINGS.containsKey(charset.name()) ||
|
||||||
"UTF-16".equals(charset.name()) ||
|
"UTF-16".equals(charset.name()) ||
|
||||||
|
|
@ -419,7 +419,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||||
Class<?> clazz = (object instanceof MappingJacksonValue ?
|
Class<?> clazz = (object instanceof MappingJacksonValue ?
|
||||||
((MappingJacksonValue) object).getValue().getClass() : object.getClass());
|
((MappingJacksonValue) object).getValue().getClass() : object.getClass());
|
||||||
ObjectMapper objectMapper = selectObjectMapper(clazz, contentType);
|
ObjectMapper objectMapper = selectObjectMapper(clazz, contentType);
|
||||||
Assert.state(objectMapper != null, "No ObjectMapper for " + clazz.getName());
|
Assert.state(objectMapper != null, () -> "No ObjectMapper for " + clazz.getName());
|
||||||
|
|
||||||
OutputStream outputStream = StreamUtils.nonClosing(outputMessage.getBody());
|
OutputStream outputStream = StreamUtils.nonClosing(outputMessage.getBody());
|
||||||
try (JsonGenerator generator = objectMapper.getFactory().createGenerator(outputStream, encoding)) {
|
try (JsonGenerator generator = objectMapper.getFactory().createGenerator(outputStream, encoding)) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -193,8 +193,7 @@ public class ResponseBodyEmitter {
|
||||||
* @throws java.lang.IllegalStateException wraps any other errors
|
* @throws java.lang.IllegalStateException wraps any other errors
|
||||||
*/
|
*/
|
||||||
public synchronized void send(Object object, @Nullable MediaType mediaType) throws IOException {
|
public synchronized void send(Object object, @Nullable MediaType mediaType) throws IOException {
|
||||||
Assert.state(!this.complete,
|
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
|
||||||
"ResponseBodyEmitter has already completed" +
|
|
||||||
(this.failure != null ? " with error: " + this.failure : ""));
|
(this.failure != null ? " with error: " + this.failure : ""));
|
||||||
sendInternal(object, mediaType);
|
sendInternal(object, mediaType);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue