|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2012 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
41 | 41 | */
|
42 | 42 | public class StringHttpMessageConverter extends AbstractHttpMessageConverter<String> {
|
43 | 43 |
|
44 |
| - public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1"); |
| 44 | + private final Charset defaultCharset; |
45 | 45 |
|
46 | 46 | private final List<Charset> availableCharsets;
|
47 | 47 |
|
48 | 48 | private boolean writeAcceptCharset = true;
|
49 | 49 |
|
| 50 | + /** |
| 51 | + * A default constructor that uses {@code "ISO-8859-1"} as the default charset. |
| 52 | + * @see #StringHttpMessageConverter(Charset) |
| 53 | + */ |
50 | 54 | public StringHttpMessageConverter() {
|
51 |
| - super(new MediaType("text", "plain", DEFAULT_CHARSET), MediaType.ALL); |
| 55 | + this(Charset.forName("ISO-8859-1")); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * A constructor accepting a default charset to use if the requested content |
| 60 | + * type does not specify one. |
| 61 | + */ |
| 62 | + public StringHttpMessageConverter(Charset defaultCharset) { |
| 63 | + super(new MediaType("text", "plain", defaultCharset), MediaType.ALL); |
| 64 | + this.defaultCharset = defaultCharset; |
52 | 65 | this.availableCharsets = new ArrayList<Charset>(Charset.availableCharsets().values());
|
53 | 66 | }
|
54 | 67 |
|
@@ -108,7 +121,7 @@ private Charset getContentTypeCharset(MediaType contentType) {
|
108 | 121 | return contentType.getCharSet();
|
109 | 122 | }
|
110 | 123 | else {
|
111 |
| - return DEFAULT_CHARSET; |
| 124 | + return this.defaultCharset; |
112 | 125 | }
|
113 | 126 | }
|
114 | 127 |
|
|
0 commit comments