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:
parent
8b5cc3256d
commit
bc5b836103
|
@ -18,6 +18,9 @@ package com.google.gson;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for the {@link JsonObject} class.
|
* Unit test for the {@link JsonObject} class.
|
||||||
*
|
*
|
||||||
|
@ -110,4 +113,14 @@ public class JsonObjectTest extends TestCase {
|
||||||
assertEquals(String.valueOf(value), jsonElement.getAsString());
|
assertEquals(String.valueOf(value), jsonElement.getAsString());
|
||||||
assertEquals(value, jsonElement.getAsCharacter());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user