Merge branch '5.3.x'

This commit is contained in:
Arjen Poutsma
2022-06-13 14:02:02 +02:00
2 changed files with 42 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.http.codec.xml;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -187,7 +188,8 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {
try {
Iterator<Object> eventReader = inputFactory.createXMLEventReader(dataBuffer.asInputStream());
Iterator<Object> eventReader = inputFactory.createXMLEventReader(dataBuffer.asInputStream(),
encoding(mimeType));
List<XMLEvent> events = new ArrayList<>();
eventReader.forEachRemaining(event -> events.add((XMLEvent) event));
return unmarshal(events, targetType.toClass());
@@ -209,6 +211,20 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
}
}
@Nullable
private static String encoding(@Nullable MimeType mimeType) {
if (mimeType == null) {
return null;
}
Charset charset = mimeType.getCharset();
if (charset == null) {
return null;
}
else {
return charset.name();
}
}
private Object unmarshal(List<XMLEvent> events, Class<?> outputClass) {
try {
Unmarshaller unmarshaller = initUnmarshaller(outputClass);