Changed version to 1.3
Made JsonParser.parse a non-static method.
This commit is contained in:
parent
8965d31ce9
commit
2034090b15
@ -4,7 +4,7 @@
|
|||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.3b3</version>
|
<version>1.3</version>
|
||||||
<inceptionYear>2008</inceptionYear>
|
<inceptionYear>2008</inceptionYear>
|
||||||
<name>Gson</name>
|
<name>Gson</name>
|
||||||
<url>http://code.google.com/p/google-gson/</url>
|
<url>http://code.google.com/p/google-gson/</url>
|
||||||
|
@ -374,7 +374,7 @@ public final class Gson {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T fromJson(Reader json, Type typeOfT) throws JsonParseException {
|
public <T> T fromJson(Reader json, Type typeOfT) throws JsonParseException {
|
||||||
try {
|
try {
|
||||||
JsonElement root = JsonParser.parse(json);
|
JsonElement root = new JsonParser().parse(json);
|
||||||
JsonDeserializationContext context = new JsonDeserializationContextDefault(
|
JsonDeserializationContext context = new JsonDeserializationContextDefault(
|
||||||
createDefaultObjectNavigatorFactory(), deserializers, objectConstructor);
|
createDefaultObjectNavigatorFactory(), deserializers, objectConstructor);
|
||||||
T target = (T) context.deserialize(root, typeOfT);
|
T target = (T) context.deserialize(root, typeOfT);
|
||||||
|
@ -35,7 +35,7 @@ public final class JsonParser {
|
|||||||
* @throws JsonParseException if the specified text is not valid JSON
|
* @throws JsonParseException if the specified text is not valid JSON
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public static JsonElement parse(String json) throws JsonParseException {
|
public JsonElement parse(String json) throws JsonParseException {
|
||||||
return parse(new StringReader(json));
|
return parse(new StringReader(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public final class JsonParser {
|
|||||||
* @throws JsonParseException if the specified text is not valid JSON
|
* @throws JsonParseException if the specified text is not valid JSON
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public static JsonElement parse(Reader json) throws JsonParseException {
|
public JsonElement parse(Reader json) throws JsonParseException {
|
||||||
try {
|
try {
|
||||||
JsonParserImpl parser = new JsonParserImpl(json);
|
JsonParserImpl parser = new JsonParserImpl(json);
|
||||||
return parser.parse();
|
return parser.parse();
|
||||||
|
@ -228,7 +228,7 @@ final class JsonPrintFormatter implements JsonFormatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endObject(JsonObject object) throws IOException {
|
public void endObject(JsonObject object) {
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,17 @@ import java.io.StringReader;
|
|||||||
*/
|
*/
|
||||||
public class JsonParserTest extends TestCase {
|
public class JsonParserTest extends TestCase {
|
||||||
|
|
||||||
|
private JsonParser parser;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
parser = new JsonParser();
|
||||||
|
}
|
||||||
|
|
||||||
public void testParseString() {
|
public void testParseString() {
|
||||||
String json = "{a:10,b:'c'}";
|
String json = "{a:10,b:'c'}";
|
||||||
JsonElement e = JsonParser.parse(json);
|
JsonElement e = parser.parse(json);
|
||||||
assertTrue(e.isJsonObject());
|
assertTrue(e.isJsonObject());
|
||||||
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
|
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
|
||||||
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
||||||
@ -21,7 +29,7 @@ public class JsonParserTest extends TestCase {
|
|||||||
|
|
||||||
public void testParseReader() {
|
public void testParseReader() {
|
||||||
StringReader reader = new StringReader("{a:10,b:'c'}");
|
StringReader reader = new StringReader("{a:10,b:'c'}");
|
||||||
JsonElement e = JsonParser.parse(reader);
|
JsonElement e = parser.parse(reader);
|
||||||
assertTrue(e.isJsonObject());
|
assertTrue(e.isJsonObject());
|
||||||
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
|
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
|
||||||
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
||||||
|
@ -99,7 +99,7 @@ public class JsonParserTest extends TestCase {
|
|||||||
public void testChangingCustomTreeAndDeserializing() {
|
public void testChangingCustomTreeAndDeserializing() {
|
||||||
StringReader json =
|
StringReader json =
|
||||||
new StringReader("{'stringValue':'no message','intValue':10,'longValue':20}");
|
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.remove("stringValue");
|
||||||
obj.addProperty("stringValue", "fooBar");
|
obj.addProperty("stringValue", "fooBar");
|
||||||
BagOfPrimitives target = gson.fromJson(obj, BagOfPrimitives.class);
|
BagOfPrimitives target = gson.fromJson(obj, BagOfPrimitives.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user