renamed com.google.gson.stream.JsonSyntaxException to MalformedJsonException.
Throwing JsonSyntaxException instead of JsonParseException where we can detect a syntax error.
This commit is contained in:
parent
c8c3a6965c
commit
abe244c099
@ -278,7 +278,7 @@ final class DefaultTypeAdapters {
|
||||
return format.parse(json.getAsString());
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ final class DefaultTypeAdapters {
|
||||
return new java.sql.Date(date.getTime());
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -351,7 +351,7 @@ final class DefaultTypeAdapters {
|
||||
return new Time(date.getTime());
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -425,7 +425,7 @@ final class DefaultTypeAdapters {
|
||||
try {
|
||||
return new URL(json.getAsString());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ final class DefaultTypeAdapters {
|
||||
try {
|
||||
return new URI(json.getAsString());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.google.gson;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -24,6 +22,10 @@ import java.io.StringReader;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.MalformedJsonException;
|
||||
|
||||
/**
|
||||
* A streaming parser that allows reading of multiple {@link JsonElement}s from the specified reader
|
||||
* asynchronously.
|
||||
@ -101,8 +103,10 @@ public final class JsonStreamParser implements Iterator<JsonElement> {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
return parser.peek() != JsonToken.END_DOCUMENT;
|
||||
} catch (MalformedJsonException e) {
|
||||
throw new JsonSyntaxException(e);
|
||||
} catch (IOException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonIOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
package com.google.gson;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonSyntaxException;
|
||||
import com.google.gson.stream.MalformedJsonException;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.EOFException;
|
||||
@ -71,12 +71,12 @@ final class Streams {
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
return JsonNull.createJsonNull();
|
||||
} catch (JsonSyntaxException e) {
|
||||
throw new JsonParseException(e);
|
||||
} catch (MalformedJsonException e) {
|
||||
throw new JsonSyntaxException(e);
|
||||
} catch (IOException e) {
|
||||
throw new JsonIOException(e);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new JsonParseException(e);
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1104,7 @@ public final class JsonReader implements Closeable {
|
||||
* with this reader's content.
|
||||
*/
|
||||
private IOException syntaxError(String message) throws IOException {
|
||||
throw new JsonSyntaxException(message + " near " + getSnippet());
|
||||
throw new MalformedJsonException(message + " near " + getSnippet());
|
||||
}
|
||||
|
||||
private CharSequence getSnippet() {
|
||||
|
@ -22,8 +22,8 @@ import java.io.IOException;
|
||||
* Thrown when a reader encounters malformed JSON. Some syntax errors can be
|
||||
* ignored by calling {@link JsonReader#setLenient(boolean)}.
|
||||
*/
|
||||
public final class JsonSyntaxException extends IOException {
|
||||
public JsonSyntaxException(String s) {
|
||||
public final class MalformedJsonException extends IOException {
|
||||
public MalformedJsonException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user