Removed a bunch of unused code and unnecessary else statements.

This commit is contained in:
Inderjeet Singh 2010-09-28 13:42:43 +00:00
parent e656954c16
commit 2b1f3eec15
24 changed files with 79 additions and 161 deletions

View File

@ -127,9 +127,8 @@ class Escaper {
char c = (char) codepoint; char c = (char) codepoint;
return JS_ESCAPE_CHARS.contains(c) return JS_ESCAPE_CHARS.contains(c)
|| (escapeHtmlCharacters && HTML_ESCAPE_CHARS.contains(c)); || (escapeHtmlCharacters && HTML_ESCAPE_CHARS.contains(c));
} else {
return false;
} }
return false;
} }
private static boolean isControlCharacter(int codePoint) { private static boolean isControlCharacter(int codePoint) {

View File

@ -56,13 +56,12 @@ final class GenericArrayTypeImpl implements GenericArrayType {
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof GenericArrayType)) { if (!(o instanceof GenericArrayType)) {
return false; return false;
} else { }
GenericArrayType that = (GenericArrayType) o; GenericArrayType that = (GenericArrayType) o;
Type thatComponentType = that.getGenericComponentType(); Type thatComponentType = that.getGenericComponentType();
return genericComponentType == null ? return genericComponentType == null ?
thatComponentType == null : genericComponentType.equals(thatComponentType); thatComponentType == null : genericComponentType.equals(thatComponentType);
} }
}
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -87,7 +87,6 @@ public final class Gson {
new SyntheticFieldExclusionStrategy(true); new SyntheticFieldExclusionStrategy(true);
static final ModifierBasedExclusionStrategy DEFAULT_MODIFIER_BASED_EXCLUSION_STRATEGY = static final ModifierBasedExclusionStrategy DEFAULT_MODIFIER_BASED_EXCLUSION_STRATEGY =
new ModifierBasedExclusionStrategy(new int[] { Modifier.TRANSIENT, Modifier.STATIC }); new ModifierBasedExclusionStrategy(new int[] { Modifier.TRANSIENT, Modifier.STATIC });
static final JsonFormatter DEFAULT_JSON_FORMATTER = new JsonCompactFormatter();
static final FieldNamingStrategy2 DEFAULT_NAMING_POLICY = static final FieldNamingStrategy2 DEFAULT_NAMING_POLICY =
new SerializedNameAnnotationInterceptingNamingPolicy(new JavaFieldNamingPolicy()); new SerializedNameAnnotationInterceptingNamingPolicy(new JavaFieldNamingPolicy());
@ -109,7 +108,6 @@ public final class Gson {
/** Map containing Type or Class objects as keys */ /** Map containing Type or Class objects as keys */
private final ParameterizedTypeHandlerMap<JsonDeserializer<?>> deserializers; private final ParameterizedTypeHandlerMap<JsonDeserializer<?>> deserializers;
private final JsonFormatter formatter;
private final boolean serializeNulls; private final boolean serializeNulls;
private final boolean htmlSafe; private final boolean htmlSafe;
@ -152,21 +150,19 @@ public final class Gson {
public Gson() { public Gson() {
this(DEFAULT_EXCLUSION_STRATEGY, DEFAULT_EXCLUSION_STRATEGY, DEFAULT_NAMING_POLICY, this(DEFAULT_EXCLUSION_STRATEGY, DEFAULT_EXCLUSION_STRATEGY, DEFAULT_NAMING_POLICY,
new MappedObjectConstructor(DefaultTypeAdapters.getDefaultInstanceCreators()), new MappedObjectConstructor(DefaultTypeAdapters.getDefaultInstanceCreators()),
DEFAULT_JSON_FORMATTER, false, DefaultTypeAdapters.getDefaultSerializers(), false, DefaultTypeAdapters.getDefaultSerializers(),
DefaultTypeAdapters.getDefaultDeserializers(), DEFAULT_JSON_NON_EXECUTABLE, true); DefaultTypeAdapters.getDefaultDeserializers(), DEFAULT_JSON_NON_EXECUTABLE, true);
} }
Gson(ExclusionStrategy serializationStrategy, ExclusionStrategy deserializationStrategy, Gson(ExclusionStrategy serializationStrategy, ExclusionStrategy deserializationStrategy,
FieldNamingStrategy2 fieldNamingPolicy, MappedObjectConstructor objectConstructor, FieldNamingStrategy2 fieldNamingPolicy, MappedObjectConstructor objectConstructor,
JsonFormatter formatter, boolean serializeNulls, boolean serializeNulls, ParameterizedTypeHandlerMap<JsonSerializer<?>> serializers,
ParameterizedTypeHandlerMap<JsonSerializer<?>> serializers,
ParameterizedTypeHandlerMap<JsonDeserializer<?>> deserializers, ParameterizedTypeHandlerMap<JsonDeserializer<?>> deserializers,
boolean generateNonExecutableGson, boolean htmlSafe) { boolean generateNonExecutableGson, boolean htmlSafe) {
this.serializationStrategy = serializationStrategy; this.serializationStrategy = serializationStrategy;
this.deserializationStrategy = deserializationStrategy; this.deserializationStrategy = deserializationStrategy;
this.fieldNamingPolicy = fieldNamingPolicy; this.fieldNamingPolicy = fieldNamingPolicy;
this.objectConstructor = objectConstructor; this.objectConstructor = objectConstructor;
this.formatter = formatter;
this.serializeNulls = serializeNulls; this.serializeNulls = serializeNulls;
this.serializers = serializers; this.serializers = serializers;
this.deserializers = deserializers; this.deserializers = deserializers;

View File

@ -542,10 +542,8 @@ public final class GsonBuilder {
MappedObjectConstructor objConstructor = new MappedObjectConstructor(customInstanceCreators); MappedObjectConstructor objConstructor = new MappedObjectConstructor(customInstanceCreators);
JsonFormatter formatter = prettyPrinting ?
new JsonPrintFormatter(escapeHtmlChars) : new JsonCompactFormatter(escapeHtmlChars);
Gson gson = new Gson(serializationExclusionStrategy, deserializationExclusionStrategy, Gson gson = new Gson(serializationExclusionStrategy, deserializationExclusionStrategy,
fieldNamingPolicy, objConstructor, formatter, serializeNulls, customSerializers, fieldNamingPolicy, objConstructor, serializeNulls, customSerializers,
customDeserializers, generateNonExecutableJson, escapeHtmlChars); customDeserializers, generateNonExecutableJson, escapeHtmlChars);
return gson; return gson;
} }

View File

@ -51,9 +51,9 @@ final class JsonArrayDeserializationVisitor<T> extends JsonDeserializationVisito
// this typecasting is safe. // this typecasting is safe.
return (T) objectConstructor.constructArray(arrayTypeInfo.getSecondLevelType(), return (T) objectConstructor.constructArray(arrayTypeInfo.getSecondLevelType(),
jsonArray.size()); jsonArray.size());
} else { // is a collection
return (T) objectConstructor.construct(typeInfo.getRawClass());
} }
// is a collection
return (T) objectConstructor.construct(typeInfo.getRawClass());
} }
public void visitArray(Object array, Type arrayType) { public void visitArray(Object array, Type arrayType) {

View File

@ -79,9 +79,8 @@ public abstract class JsonElement {
public JsonObject getAsJsonObject() { public JsonObject getAsJsonObject() {
if (isJsonObject()) { if (isJsonObject()) {
return (JsonObject) this; return (JsonObject) this;
} else {
throw new IllegalStateException("This is not a JSON Object.");
} }
throw new IllegalStateException("This is not a JSON Object.");
} }
/** /**
@ -96,9 +95,8 @@ public abstract class JsonElement {
public JsonArray getAsJsonArray() { public JsonArray getAsJsonArray() {
if (isJsonArray()) { if (isJsonArray()) {
return (JsonArray) this; return (JsonArray) this;
} else {
throw new IllegalStateException("This is not a JSON Array.");
} }
throw new IllegalStateException("This is not a JSON Array.");
} }
/** /**
@ -113,9 +111,8 @@ public abstract class JsonElement {
public JsonPrimitive getAsJsonPrimitive() { public JsonPrimitive getAsJsonPrimitive() {
if (isJsonPrimitive()) { if (isJsonPrimitive()) {
return (JsonPrimitive) this; return (JsonPrimitive) this;
} else {
throw new IllegalStateException("This is not a JSON Primitive.");
} }
throw new IllegalStateException("This is not a JSON Primitive.");
} }
/** /**
@ -131,9 +128,8 @@ public abstract class JsonElement {
public JsonNull getAsJsonNull() { public JsonNull getAsJsonNull() {
if (isJsonNull()) { if (isJsonNull()) {
return (JsonNull) this; return (JsonNull) this;
} else {
throw new IllegalStateException("This is not a JSON Null.");
} }
throw new IllegalStateException("This is not a JSON Null.");
} }
/** /**

View File

@ -50,8 +50,7 @@ class JsonFieldNameValidator {
Matcher matcher = JSON_FIELD_NAME_PATTERN.matcher(fieldName); Matcher matcher = JSON_FIELD_NAME_PATTERN.matcher(fieldName);
if (!matcher.matches()) { if (!matcher.matches()) {
throw new IllegalArgumentException(fieldName + " is not a valid JSON field name."); throw new IllegalArgumentException(fieldName + " is not a valid JSON field name.");
} else { }
return fieldName; return fieldName;
} }
}
} }

View File

@ -121,11 +121,7 @@ public final class JsonObject extends JsonElement {
* @return a {@link JsonPrimitive} if the {@code value} is not null, otherwise a {@link JsonNull} * @return a {@link JsonPrimitive} if the {@code value} is not null, otherwise a {@link JsonNull}
*/ */
private JsonElement createJsonElement(Object value) { private JsonElement createJsonElement(Object value) {
if (value == null) { return value == null ? JsonNull.createJsonNull() : new JsonPrimitive(value);
return JsonNull.createJsonNull();
} else {
return new JsonPrimitive(value);
}
} }
/** /**
@ -158,9 +154,8 @@ public final class JsonObject extends JsonElement {
if (members.containsKey(memberName)) { if (members.containsKey(memberName)) {
JsonElement member = members.get(memberName); JsonElement member = members.get(memberName);
return member == null ? JsonNull.createJsonNull() : member; return member == null ? JsonNull.createJsonNull() : member;
} else {
return null;
} }
return null;
} }
/** /**

View File

@ -71,9 +71,8 @@ public final class JsonParser {
} catch (JsonParseException e) { } catch (JsonParseException e) {
if (e.getCause() instanceof EOFException) { if (e.getCause() instanceof EOFException) {
return JsonNull.createJsonNull(); return JsonNull.createJsonNull();
} else {
throw e;
} }
throw e;
} finally { } finally {
json.setLenient(lenient); json.setLenient(lenient);
} }

View File

@ -126,11 +126,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public boolean getAsBoolean() { public boolean getAsBoolean() {
if (isBoolean()) { return isBoolean() ? getAsBooleanWrapper().booleanValue() : Boolean.parseBoolean(getAsString());
return getAsBooleanWrapper().booleanValue();
} else {
return Boolean.parseBoolean(getAsString());
}
} }
/** /**
@ -158,9 +154,8 @@ public final class JsonPrimitive extends JsonElement {
long longValue = Long.parseLong(value); long longValue = Long.parseLong(value);
if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) { if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
return (int) longValue; return (int) longValue;
} else {
return longValue;
} }
return longValue;
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
} }
@ -205,11 +200,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public double getAsDouble() { public double getAsDouble() {
if (isNumber()) { return isNumber() ? getAsNumber().doubleValue() : Double.parseDouble(getAsString());
return getAsNumber().doubleValue();
} else {
return Double.parseDouble(getAsString());
}
} }
/** /**
@ -220,11 +211,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public BigDecimal getAsBigDecimal() { public BigDecimal getAsBigDecimal() {
if (value instanceof BigDecimal) { return value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString());
return (BigDecimal) value;
} else {
return new BigDecimal(value.toString());
}
} }
/** /**
@ -235,11 +222,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public BigInteger getAsBigInteger() { public BigInteger getAsBigInteger() {
if (value instanceof BigInteger) { return value instanceof BigInteger ? (BigInteger) value : new BigInteger(value.toString());
return (BigInteger) value;
} else {
return new BigInteger(value.toString());
}
} }
/** /**
@ -250,11 +233,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public float getAsFloat() { public float getAsFloat() {
if (isNumber()) { return isNumber() ? getAsNumber().floatValue() : Float.parseFloat(getAsString());
return getAsNumber().floatValue();
} else {
return Float.parseFloat(getAsString());
}
} }
/** /**
@ -265,11 +244,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public long getAsLong() { public long getAsLong() {
if (isNumber()) { return isNumber() ? getAsNumber().longValue() : Long.parseLong(getAsString());
return getAsNumber().longValue();
} else {
return Long.parseLong(getAsString());
}
} }
/** /**
@ -280,11 +255,7 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public short getAsShort() { public short getAsShort() {
if (isNumber()) { return isNumber() ? getAsNumber().shortValue() : Short.parseShort(getAsString());
return getAsNumber().shortValue();
} else {
return Short.parseShort(getAsString());
}
} }
/** /**
@ -295,20 +266,12 @@ public final class JsonPrimitive extends JsonElement {
*/ */
@Override @Override
public int getAsInt() { public int getAsInt() {
if (isNumber()) { return isNumber() ? getAsNumber().intValue() : Integer.parseInt(getAsString());
return getAsNumber().intValue();
} else {
return Integer.parseInt(getAsString());
}
} }
@Override @Override
public byte getAsByte() { public byte getAsByte() {
if (isNumber()) { return isNumber() ? getAsNumber().byteValue() : Byte.parseByte(getAsString());
return getAsNumber().byteValue();
} else {
return Byte.parseByte(getAsString());
}
} }
@Override @Override

View File

@ -161,9 +161,8 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
if (element != null) { if (element != null) {
assignToRoot(element); assignToRoot(element);
return true; return true;
} else {
return false;
} }
return false;
} catch (CircularReferenceException e) { } catch (CircularReferenceException e) {
throw e.createDetailedException(null); throw e.createDetailedException(null);
} }
@ -205,9 +204,8 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
if (child != null) { if (child != null) {
addChildAsElement(f, child); addChildAsElement(f, child);
return true; return true;
} else {
return false;
} }
return false;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException(); throw new RuntimeException();
} catch (CircularReferenceException e) { } catch (CircularReferenceException e) {

View File

@ -88,11 +88,7 @@ public final class JsonStreamParser implements Iterator<JsonElement> {
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
throw new JsonParseException("Failed parsing JSON source to Json", e); throw new JsonParseException("Failed parsing JSON source to Json", e);
} catch (JsonParseException e) { } catch (JsonParseException e) {
if (e.getCause() instanceof EOFException) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e;
throw new NoSuchElementException();
} else {
throw e;
}
} }
} }

View File

@ -100,10 +100,8 @@ final class ModifyFirstLetterNamingPolicy extends RecursiveFieldNamingPolicy {
} }
private String modifyString(char firstCharacter, String srcString, int indexOfSubstring) { private String modifyString(char firstCharacter, String srcString, int indexOfSubstring) {
if (indexOfSubstring < srcString.length()) { return indexOfSubstring < srcString.length() ?
return firstCharacter + srcString.substring(indexOfSubstring); firstCharacter + srcString.substring(indexOfSubstring)
} else { : String.valueOf(firstCharacter);
return String.valueOf(firstCharacter);
}
} }
} }

View File

@ -152,7 +152,7 @@ final class ObjectNavigator {
if (exclusionStrategy.shouldSkipField(fieldAttributes) if (exclusionStrategy.shouldSkipField(fieldAttributes)
|| exclusionStrategy.shouldSkipClass(fieldAttributes.getDeclaredClass())) { || exclusionStrategy.shouldSkipClass(fieldAttributes.getDeclaredClass())) {
continue; // skip continue; // skip
} else { }
TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.type); TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.type);
Type declaredTypeOfField = fieldTypeInfo.getActualType(); Type declaredTypeOfField = fieldTypeInfo.getActualType();
boolean visitedWithCustomHandler = boolean visitedWithCustomHandler =
@ -166,5 +166,4 @@ final class ObjectNavigator {
} }
} }
} }
}
} }

View File

@ -68,12 +68,12 @@ final class ParameterizedTypeImpl implements ParameterizedType {
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof ParameterizedType)) { if (!(o instanceof ParameterizedType)) {
return false; return false;
} else { }
// Check that information is equivalent // Check that information is equivalent
ParameterizedType that = (ParameterizedType) o; ParameterizedType that = (ParameterizedType) o;
if (this == that) if (this == that) {
return true; return true;
}
Type thatOwner = that.getOwnerType(); Type thatOwner = that.getOwnerType();
Type thatRawType = that.getRawType(); Type thatRawType = that.getRawType();
@ -81,7 +81,6 @@ final class ParameterizedTypeImpl implements ParameterizedType {
&& (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) && (rawType == null ? thatRawType == null : rawType.equals(thatRawType))
&& Arrays.equals(actualTypeArguments, that.getActualTypeArguments()); && Arrays.equals(actualTypeArguments, that.getActualTypeArguments());
} }
}
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -42,10 +42,7 @@ final class SerializedNameAnnotationInterceptingNamingPolicy implements FieldNam
public String translateName(FieldAttributes f) { public String translateName(FieldAttributes f) {
Preconditions.checkNotNull(f); Preconditions.checkNotNull(f);
SerializedName serializedName = f.getAnnotation(SerializedName.class); SerializedName serializedName = f.getAnnotation(SerializedName.class);
if (serializedName != null) { return serializedName == null ? delegate.translateName(f)
return fieldNameValidator.validate(serializedName.value()); : fieldNameValidator.validate(serializedName.value());
} else {
return delegate.translateName(f);
}
} }
} }

View File

@ -40,12 +40,8 @@ final class TypeInfoArray extends TypeInfo {
} }
private static Type extractSecondLevelType(Type actualType, Class<?> rawClass) { private static Type extractSecondLevelType(Type actualType, Class<?> rawClass) {
if (actualType instanceof GenericArrayType) { return actualType instanceof GenericArrayType ?
GenericArrayType castedType = (GenericArrayType) actualType; ((GenericArrayType) actualType).getGenericComponentType() : rawClass.getComponentType();
return castedType.getGenericComponentType();
} else {
return rawClass.getComponentType();
}
} }
/** /**

View File

@ -72,13 +72,10 @@ final class TypeInfoFactory {
Type actualType = getActualType(componentType, parentType, rawParentClass); Type actualType = getActualType(componentType, parentType, rawParentClass);
if (componentType.equals(actualType)) { if (componentType.equals(actualType)) {
return castedType; return castedType;
} else {
if (actualType instanceof Class<?>) {
return TypeUtils.wrapWithArray(TypeUtils.toRawClass(actualType));
} else {
return new GenericArrayTypeImpl(actualType);
}
} }
return actualType instanceof Class<?> ?
TypeUtils.wrapWithArray(TypeUtils.toRawClass(actualType))
: new GenericArrayTypeImpl(actualType);
} else if (typeToEvaluate instanceof TypeVariable<?>) { } else if (typeToEvaluate instanceof TypeVariable<?>) {
if (parentType instanceof ParameterizedType) { if (parentType instanceof ParameterizedType) {
// The class definition has the actual types used for the type variables. // The class definition has the actual types used for the type variables.
@ -93,11 +90,10 @@ final class TypeInfoFactory {
int indexOfActualTypeArgument = getIndex(classTypeVariables, fieldTypeVariable); int indexOfActualTypeArgument = getIndex(classTypeVariables, fieldTypeVariable);
Type[] actualTypeArguments = objParameterizedType.getActualTypeArguments(); Type[] actualTypeArguments = objParameterizedType.getActualTypeArguments();
return actualTypeArguments[indexOfActualTypeArgument]; return actualTypeArguments[indexOfActualTypeArgument];
} else { }
throw new UnsupportedOperationException("Expecting parameterized type, got " + parentType throw new UnsupportedOperationException("Expecting parameterized type, got " + parentType
+ ".\n Are you missing the use of TypeToken idiom?\n See " + ".\n Are you missing the use of TypeToken idiom?\n See "
+ "http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener"); + "http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener");
}
} else if (typeToEvaluate instanceof WildcardType) { } else if (typeToEvaluate instanceof WildcardType) {
WildcardType castedType = (WildcardType) typeToEvaluate; WildcardType castedType = (WildcardType) typeToEvaluate;
return getActualType(castedType.getUpperBounds()[0], parentType, rawParentClass); return getActualType(castedType.getUpperBounds()[0], parentType, rawParentClass);

View File

@ -381,9 +381,8 @@ public final class JsonReader implements Closeable {
JsonToken token = nextValue(); JsonToken token = nextValue();
if (lenient) { if (lenient) {
return token; return token;
} else {
throw syntaxError("Expected EOF");
} }
throw syntaxError("Expected EOF");
} catch (EOFException e) { } catch (EOFException e) {
hasToken = true; // TODO: avoid throwing here? hasToken = true; // TODO: avoid throwing here?
return token = JsonToken.END_DOCUMENT; return token = JsonToken.END_DOCUMENT;

View File

@ -41,7 +41,7 @@ public class FunctionWithInternalDependenciesTest extends TestCase {
ExclusionStrategy exclusionStrategy = new DisjunctionExclusionStrategy(strategies); ExclusionStrategy exclusionStrategy = new DisjunctionExclusionStrategy(strategies);
Gson gson = new Gson(exclusionStrategy, exclusionStrategy, Gson.DEFAULT_NAMING_POLICY, Gson gson = new Gson(exclusionStrategy, exclusionStrategy, Gson.DEFAULT_NAMING_POLICY,
new MappedObjectConstructor(DefaultTypeAdapters.getDefaultInstanceCreators()), new MappedObjectConstructor(DefaultTypeAdapters.getDefaultInstanceCreators()),
Gson.DEFAULT_JSON_FORMATTER, false, DefaultTypeAdapters.getDefaultSerializers(), false, DefaultTypeAdapters.getDefaultSerializers(),
DefaultTypeAdapters.getDefaultDeserializers(), Gson.DEFAULT_JSON_NON_EXECUTABLE, true); DefaultTypeAdapters.getDefaultDeserializers(), Gson.DEFAULT_JSON_NON_EXECUTABLE, true);
assertEquals("{}", gson.toJson(new ClassWithNoFields() { assertEquals("{}", gson.toJson(new ClassWithNoFields() {
// empty anonymous class // empty anonymous class

View File

@ -223,7 +223,7 @@ public final class MixedStreamTest extends TestCase {
this.color = color; this.color = color;
} }
@SuppressWarnings("unused") // used by Gson // used by Gson
Car() {} Car() {}
@Override public int hashCode() { @Override public int hashCode() {

View File

@ -39,9 +39,8 @@ final class PrimitiveTypeAdapter {
String value = from.toString(); String value = from.toString();
if (value.length() == 1) { if (value.length() == 1) {
return (T) (Character) from.toString().charAt(0); return (T) (Character) from.toString().charAt(0);
} else {
throw new JsonParseException("The value: " + value + " contains more than a character.");
} }
throw new JsonParseException("The value: " + value + " contains more than a character.");
} }
try { try {

View File

@ -233,11 +233,10 @@ public class CustomTypeAdaptersTest extends TestCase {
customDeserializerInvoked.value = true; customDeserializerInvoked.value = true;
if (json == null || json.isJsonNull()) { if (json == null || json.isJsonNull()) {
return null; return null;
} else { }
Number number = json.getAsJsonPrimitive().getAsNumber(); Number number = json.getAsJsonPrimitive().getAsNumber();
return number == null ? null : number.longValue(); return number == null ? null : number.longValue();
} }
}
}).create(); }).create();
String json = "{'value':null}"; String json = "{'value':null}";
ClassWithWrapperLongField target = gson.fromJson(json, ClassWithWrapperLongField.class); ClassWithWrapperLongField target = gson.fromJson(json, ClassWithWrapperLongField.class);

View File

@ -16,19 +16,17 @@
package com.google.gson.functional; package com.google.gson.functional;
import com.google.gson.Gson;
import com.google.gson.common.MoreAsserts;
import com.google.gson.reflect.TypeToken;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
import junit.framework.TestCase;
import com.google.gson.Gson;
import com.google.gson.common.MoreAsserts;
import com.google.gson.reflect.TypeToken;
/** /**
* Functional tests for Java 5.0 enums. * Functional tests for Java 5.0 enums.