Changed version to 1.3

Made JsonParser.parse a non-static method.
This commit is contained in:
Inderjeet Singh 2009-03-31 17:53:23 +00:00
parent 8965d31ce9
commit 2034090b15
6 changed files with 16 additions and 8 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<packaging>jar</packaging>
<version>1.3b3</version>
<version>1.3</version>
<inceptionYear>2008</inceptionYear>
<name>Gson</name>
<url>http://code.google.com/p/google-gson/</url>

View File

@ -374,7 +374,7 @@ public final class Gson {
@SuppressWarnings("unchecked")
public <T> T fromJson(Reader json, Type typeOfT) throws JsonParseException {
try {
JsonElement root = JsonParser.parse(json);
JsonElement root = new JsonParser().parse(json);
JsonDeserializationContext context = new JsonDeserializationContextDefault(
createDefaultObjectNavigatorFactory(), deserializers, objectConstructor);
T target = (T) context.deserialize(root, typeOfT);

View File

@ -35,7 +35,7 @@ public final class JsonParser {
* @throws JsonParseException if the specified text is not valid JSON
* @since 1.3
*/
public static JsonElement parse(String json) throws JsonParseException {
public JsonElement parse(String json) throws JsonParseException {
return parse(new StringReader(json));
}
@ -47,7 +47,7 @@ public final class JsonParser {
* @throws JsonParseException if the specified text is not valid JSON
* @since 1.3
*/
public static JsonElement parse(Reader json) throws JsonParseException {
public JsonElement parse(Reader json) throws JsonParseException {
try {
JsonParserImpl parser = new JsonParserImpl(json);
return parser.parse();

View File

@ -228,7 +228,7 @@ final class JsonPrintFormatter implements JsonFormatter {
}
}
public void endObject(JsonObject object) throws IOException {
public void endObject(JsonObject object) {
writer.endObject();
}

View File

@ -11,9 +11,17 @@ import java.io.StringReader;
*/
public class JsonParserTest extends TestCase {
private JsonParser parser;
@Override
protected void setUp() throws Exception {
super.setUp();
parser = new JsonParser();
}
public void testParseString() {
String json = "{a:10,b:'c'}";
JsonElement e = JsonParser.parse(json);
JsonElement e = parser.parse(json);
assertTrue(e.isJsonObject());
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
@ -21,7 +29,7 @@ public class JsonParserTest extends TestCase {
public void testParseReader() {
StringReader reader = new StringReader("{a:10,b:'c'}");
JsonElement e = JsonParser.parse(reader);
JsonElement e = parser.parse(reader);
assertTrue(e.isJsonObject());
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
assertEquals("c", e.getAsJsonObject().get("b").getAsString());

View File

@ -99,7 +99,7 @@ public class JsonParserTest extends TestCase {
public void testChangingCustomTreeAndDeserializing() {
StringReader json =
new StringReader("{'stringValue':'no message','intValue':10,'longValue':20}");
JsonObject obj = (JsonObject) JsonParser.parse(json);
JsonObject obj = (JsonObject) new JsonParser().parse(json);
obj.remove("stringValue");
obj.addProperty("stringValue", "fooBar");
BagOfPrimitives target = gson.fromJson(obj, BagOfPrimitives.class);