Code cleanup (Removed spaces) (#1474)
* Removed double spaces in comments * Unified comments * Removed space * Removed spaces in code
This commit is contained in:
parent
4d942db168
commit
b75e1bbc79
@ -20,7 +20,7 @@ package com.google.gson;
|
|||||||
* A strategy (or policy) definition that is used to decide whether or not a field or top-level
|
* A strategy (or policy) definition that is used to decide whether or not a field or top-level
|
||||||
* class should be serialized or deserialized as part of the JSON output/input. For serialization,
|
* class should be serialized or deserialized as part of the JSON output/input. For serialization,
|
||||||
* if the {@link #shouldSkipClass(Class)} method returns true then that class or field type
|
* if the {@link #shouldSkipClass(Class)} method returns true then that class or field type
|
||||||
* will not be part of the JSON output. For deserialization, if {@link #shouldSkipClass(Class)}
|
* will not be part of the JSON output. For deserialization, if {@link #shouldSkipClass(Class)}
|
||||||
* returns true, then it will not be set as part of the Java object structure.
|
* returns true, then it will not be set as part of the Java object structure.
|
||||||
*
|
*
|
||||||
* <p>The following are a few examples that shows how you can use this exclusion mechanism.
|
* <p>The following are a few examples that shows how you can use this exclusion mechanism.
|
||||||
|
@ -19,9 +19,9 @@ package com.google.gson;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mechanism for providing custom field naming in Gson. This allows the client code to translate
|
* A mechanism for providing custom field naming in Gson. This allows the client code to translate
|
||||||
* field names into a particular convention that is not supported as a normal Java field
|
* field names into a particular convention that is not supported as a normal Java field
|
||||||
* declaration rules. For example, Java does not support "-" characters in a field name.
|
* declaration rules. For example, Java does not support "-" characters in a field name.
|
||||||
*
|
*
|
||||||
* @author Inderjeet Singh
|
* @author Inderjeet Singh
|
||||||
* @author Joel Leitch
|
* @author Joel Leitch
|
||||||
|
@ -80,7 +80,7 @@ import com.google.gson.stream.MalformedJsonException;
|
|||||||
*
|
*
|
||||||
* <p>If the object that your are serializing/deserializing is a {@code ParameterizedType}
|
* <p>If the object that your are serializing/deserializing is a {@code ParameterizedType}
|
||||||
* (i.e. contains at least one type parameter and may be an array) then you must use the
|
* (i.e. contains at least one type parameter and may be an array) then you must use the
|
||||||
* {@link #toJson(Object, Type)} or {@link #fromJson(String, Type)} method. Here is an
|
* {@link #toJson(Object, Type)} or {@link #fromJson(String, Type)} method. Here is an
|
||||||
* example for serializing and deserializing a {@code ParameterizedType}:
|
* example for serializing and deserializing a {@code ParameterizedType}:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -18,12 +18,12 @@ package com.google.gson;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This exception is raised if there is a serious issue that occurs during parsing of a Json
|
* This exception is raised if there is a serious issue that occurs during parsing of a Json
|
||||||
* string. One of the main usages for this class is for the Gson infrastructure. If the incoming
|
* string. One of the main usages for this class is for the Gson infrastructure. If the incoming
|
||||||
* Json is bad/malicious, an instance of this exception is raised.
|
* Json is bad/malicious, an instance of this exception is raised.
|
||||||
*
|
*
|
||||||
* <p>This exception is a {@link RuntimeException} because it is exposed to the client. Using a
|
* <p>This exception is a {@link RuntimeException} because it is exposed to the client. Using a
|
||||||
* {@link RuntimeException} avoids bad coding practices on the client side where they catch the
|
* {@link RuntimeException} avoids bad coding practices on the client side where they catch the
|
||||||
* exception and do nothing. It is often the case that you want to blow up if there is a parsing
|
* exception and do nothing. It is often the case that you want to blow up if there is a parsing
|
||||||
* error (i.e. often clients do not know how to recover from a {@link JsonParseException}.</p>
|
* error (i.e. often clients do not know how to recover from a {@link JsonParseException}.</p>
|
||||||
*
|
*
|
||||||
* @author Inderjeet Singh
|
* @author Inderjeet Singh
|
||||||
|
@ -33,7 +33,7 @@ import com.google.gson.stream.MalformedJsonException;
|
|||||||
*
|
*
|
||||||
* <p>This class is conditionally thread-safe (see Item 70, Effective Java second edition). To
|
* <p>This class is conditionally thread-safe (see Item 70, Effective Java second edition). To
|
||||||
* properly use this class across multiple threads, you will need to add some external
|
* properly use this class across multiple threads, you will need to add some external
|
||||||
* synchronization. For example:
|
* synchronization. For example:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
|
* JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
|
||||||
|
@ -27,7 +27,7 @@ package com.google.gson;
|
|||||||
public enum LongSerializationPolicy {
|
public enum LongSerializationPolicy {
|
||||||
/**
|
/**
|
||||||
* This is the "default" serialization policy that will output a {@code long} object as a JSON
|
* This is the "default" serialization policy that will output a {@code long} object as a JSON
|
||||||
* number. For example, assume an object has a long field named "f" then the serialized output
|
* number. For example, assume an object has a long field named "f" then the serialized output
|
||||||
* would be:
|
* would be:
|
||||||
* {@code {"f":123}}.
|
* {@code {"f":123}}.
|
||||||
*/
|
*/
|
||||||
@ -38,7 +38,7 @@ public enum LongSerializationPolicy {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes a long value as a quoted string. For example, assume an object has a long field
|
* Serializes a long value as a quoted string. For example, assume an object has a long field
|
||||||
* named "f" then the serialized output would be:
|
* named "f" then the serialized output would be:
|
||||||
* {@code {"f":"123"}}.
|
* {@code {"f":"123"}}.
|
||||||
*/
|
*/
|
||||||
|
@ -28,7 +28,7 @@ import java.lang.annotation.Target;
|
|||||||
*
|
*
|
||||||
* <p>This annotation will override any {@link com.google.gson.FieldNamingPolicy}, including
|
* <p>This annotation will override any {@link com.google.gson.FieldNamingPolicy}, including
|
||||||
* the default field naming policy, that may have been set on the {@link com.google.gson.Gson}
|
* the default field naming policy, that may have been set on the {@link com.google.gson.Gson}
|
||||||
* instance. A different naming policy can set using the {@code GsonBuilder} class. See
|
* instance. A different naming policy can set using the {@code GsonBuilder} class. See
|
||||||
* {@link com.google.gson.GsonBuilder#setFieldNamingPolicy(com.google.gson.FieldNamingPolicy)}
|
* {@link com.google.gson.GsonBuilder#setFieldNamingPolicy(com.google.gson.FieldNamingPolicy)}
|
||||||
* for more information.</p>
|
* for more information.</p>
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
|||||||
/**
|
/**
|
||||||
* An annotation that indicates the version number until a member or a type should be present.
|
* An annotation that indicates the version number until a member or a type should be present.
|
||||||
* Basically, if Gson is created with a version number that exceeds the value stored in the
|
* Basically, if Gson is created with a version number that exceeds the value stored in the
|
||||||
* {@code Until} annotation then the field will be ignored from the JSON output. This annotation
|
* {@code Until} annotation then the field will be ignored from the JSON output. This annotation
|
||||||
* is useful to manage versioning of your JSON classes for a web-service.
|
* is useful to manage versioning of your JSON classes for a web-service.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -31,7 +31,7 @@ import junit.framework.TestCase;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functional Test exercising custom deserialization only. When test applies to both
|
* Functional Test exercising custom deserialization only. When test applies to both
|
||||||
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
||||||
*
|
*
|
||||||
* @author Joel Leitch
|
* @author Joel Leitch
|
||||||
|
@ -33,7 +33,7 @@ import java.util.SortedSet;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functional Test exercising custom serialization only. When test applies to both
|
* Functional Test exercising custom serialization only. When test applies to both
|
||||||
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
||||||
*
|
*
|
||||||
* @author Inderjeet Singh
|
* @author Inderjeet Singh
|
||||||
|
@ -163,7 +163,7 @@ public class NullObjectAndFieldTest extends TestCase {
|
|||||||
assertFalse(target.bool2); // test the default value of a primitive boolean field per JVM spec
|
assertFalse(target.bool2); // test the default value of a primitive boolean field per JVM spec
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ClassWithInitializedMembers {
|
public static class ClassWithInitializedMembers {
|
||||||
// Using a mix of no-args constructor and field initializers
|
// Using a mix of no-args constructor and field initializers
|
||||||
// Also, some fields are intialized and some are not (so initialized per JVM spec)
|
// Also, some fields are intialized and some are not (so initialized per JVM spec)
|
||||||
public static final String MY_STRING_DEFAULT = "string";
|
public static final String MY_STRING_DEFAULT = "string";
|
||||||
|
@ -88,7 +88,7 @@ public class VersioningTest extends TestCase {
|
|||||||
public void testIgnoreLaterVersionClassDeserialization() {
|
public void testIgnoreLaterVersionClassDeserialization() {
|
||||||
Gson gson = builder.setVersion(1.0).create();
|
Gson gson = builder.setVersion(1.0).create();
|
||||||
String json = "{\"a\":3,\"b\":4,\"c\":5,\"d\":6}";
|
String json = "{\"a\":3,\"b\":4,\"c\":5,\"d\":6}";
|
||||||
Version1_2 version1_2 = gson.fromJson(json, Version1_2.class);
|
Version1_2 version1_2 = gson.fromJson(json, Version1_2.class);
|
||||||
// Since the class is versioned to be after 1.0, we expect null
|
// Since the class is versioned to be after 1.0, we expect null
|
||||||
// This is the new behavior in Gson 2.0
|
// This is the new behavior in Gson 2.0
|
||||||
assertNull(version1_2);
|
assertNull(version1_2);
|
||||||
|
@ -33,7 +33,7 @@ public final class UnsafeAllocatorInstantiationTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that the {@link java.lang.UnsupportedOperationException} is thrown when trying
|
* Ensure that the {@link java.lang.UnsupportedOperationException} is thrown when trying
|
||||||
* to instantiate an interface
|
* to instantiate an interface
|
||||||
*/
|
*/
|
||||||
public void testInterfaceInstantiation() {
|
public void testInterfaceInstantiation() {
|
||||||
@ -47,7 +47,7 @@ public final class UnsafeAllocatorInstantiationTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that the {@link java.lang.UnsupportedOperationException} is thrown when trying
|
* Ensure that the {@link java.lang.UnsupportedOperationException} is thrown when trying
|
||||||
* to instantiate an abstract class
|
* to instantiate an abstract class
|
||||||
*/
|
*/
|
||||||
public void testAbstractClassInstantiation() {
|
public void testAbstractClassInstantiation() {
|
||||||
|
@ -45,14 +45,16 @@ public class RecursiveTypesResolveTest extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Test simplest case of recursion.
|
* Test simplest case of recursion.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void testRecursiveResolveSimple() {
|
public void testRecursiveResolveSimple() {
|
||||||
TypeAdapter<Foo1> adapter = new Gson().getAdapter(Foo1.class);
|
TypeAdapter<Foo1> adapter = new Gson().getAdapter(Foo1.class);
|
||||||
assertNotNull(adapter);
|
assertNotNull(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// Real-world samples, found in Issues #603 and #440.
|
* Real-world samples, found in Issues #603 and #440.
|
||||||
//
|
*/
|
||||||
|
|
||||||
public void testIssue603PrintStream() {
|
public void testIssue603PrintStream() {
|
||||||
TypeAdapter<PrintStream> adapter = new Gson().getAdapter(PrintStream.class);
|
TypeAdapter<PrintStream> adapter = new Gson().getAdapter(PrintStream.class);
|
||||||
assertNotNull(adapter);
|
assertNotNull(adapter);
|
||||||
@ -63,9 +65,9 @@ public class RecursiveTypesResolveTest extends TestCase {
|
|||||||
assertNotNull(adapter);
|
assertNotNull(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// Tests belows check the behaviour of the methods changed for the fix
|
* Tests belows check the behaviour of the methods changed for the fix.
|
||||||
//
|
*/
|
||||||
|
|
||||||
public void testDoubleSupertype() {
|
public void testDoubleSupertype() {
|
||||||
assertEquals($Gson$Types.supertypeOf(Number.class),
|
assertEquals($Gson$Types.supertypeOf(Number.class),
|
||||||
@ -87,9 +89,9 @@ public class RecursiveTypesResolveTest extends TestCase {
|
|||||||
$Gson$Types.subtypeOf($Gson$Types.supertypeOf(Number.class)));
|
$Gson$Types.subtypeOf($Gson$Types.supertypeOf(Number.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// tests for recursion while resolving type variables
|
* Tests for recursion while resolving type variables.
|
||||||
//
|
*/
|
||||||
|
|
||||||
private static class TestType<X> {
|
private static class TestType<X> {
|
||||||
TestType<? super X> superType;
|
TestType<? super X> superType;
|
||||||
|
Loading…
Reference in New Issue
Block a user