Test demonstrating a bug reported in issue 182, wherein malformed JSON is emitted when an property name contains a double-quote.

This commit is contained in:
Jesse Wilson 2010-08-20 05:45:51 +00:00
parent 8b5cc3256d
commit bc5b836103

View File

@ -18,6 +18,9 @@ package com.google.gson;
import junit.framework.TestCase;
import java.util.HashMap;
import java.util.Map;
/**
* Unit test for the {@link JsonObject} class.
*
@ -110,4 +113,14 @@ public class JsonObjectTest extends TestCase {
assertEquals(String.valueOf(value), jsonElement.getAsString());
assertEquals(value, jsonElement.getAsCharacter());
}
/**
* From bug report http://code.google.com/p/google-gson/issues/detail?id=182
*/
public void testPropertyWithQuotes() {
JsonObject jsonObj = new JsonObject();
jsonObj.add("a\"b", new JsonPrimitive("c\"d"));
String json = new Gson().toJson(jsonObj);
assertEquals("{\"a\\\"b\":\"c\\\"d\"}", json);
}
}