Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes UTF-8 encoding when formatting JSON as a string.

This should resolve the locale-dependent double-encoding problems
which were so totally fun to track down across three or four
different configurations.
  • Loading branch information...
commit b519ac5e218a1173a3576df3430d85bf74313dcc 1 parent 4436a1e
@codahale codahale authored
View
2  pom.xml
@@ -5,7 +5,7 @@
<artifactId>xmlson</artifactId>
<name>XMLSON</name>
<description>A simple JSON and XML serialization library.</description>
- <version>1.5.1</version>
+ <version>1.5.2</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
View
2  src/main/java/com/wesabe/xmlson/JsonFormatter.java
@@ -34,7 +34,7 @@ public String format(XmlsonMember member) {
try {
final ByteArrayOutputStream output = new ByteArrayOutputStream();
format(member, output);
- return output.toString();
+ return output.toString("UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
View
14 src/test/java/com/wesabe/xmlson/tests/JsonFormatterTest.java
@@ -61,6 +61,20 @@ public void itIsFormattedAsAJsonObjectWithAProperty() throws Exception {
}
}
+ public static class An_Object_With_A_Unicode_String_Property {
+ @Test
+ public void itIsFormattedAsAJsonObjectWithAProperty() throws Exception {
+ final XmlsonObject object = new XmlsonObject("object").addProperty("key", "value あ");
+
+ assertEquals(
+ "{" +
+ "\"key\":\"value あ\"" +
+ "}",
+ format(object)
+ );
+ }
+ }
+
public static class An_Object_With_A_Multiline_String_Property {
@Test
public void itIsFormattedAsAJsonObjectWithAProperty() throws Exception {
Please sign in to comment.
Something went wrong with that request. Please try again.