Made FieldNamingStrategy2 is package protected class.
Made type hierarchy adapter registration package protected. Marked some of the classes final. Minor changes in the performance tests.
This commit is contained in:
parent
89c18452ae
commit
dc60cb1931
|
@ -26,9 +26,7 @@ import java.lang.reflect.Field;
|
|||
* @author Inderjeet Singh
|
||||
* @author Joel Leitch
|
||||
* @since 1.3
|
||||
* @deprecated use {@link FieldNamingStrategy2} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface FieldNamingStrategy {
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,9 +24,9 @@ package com.google.gson;
|
|||
*
|
||||
* @author Inderjeet Singh
|
||||
* @author Joel Leitch
|
||||
* @since 1.4
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface FieldNamingStrategy2 {
|
||||
interface FieldNamingStrategy2 {
|
||||
|
||||
/**
|
||||
* Translates the field name into its JSON field name representation.
|
||||
|
|
|
@ -23,7 +23,7 @@ package com.google.gson;
|
|||
* @author Inderjeet Singh
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class FieldNamingStrategy2Adapter implements FieldNamingStrategy2 {
|
||||
final class FieldNamingStrategy2Adapter implements FieldNamingStrategy2 {
|
||||
private final FieldNamingStrategy adaptee;
|
||||
|
||||
public FieldNamingStrategy2Adapter(FieldNamingStrategy adaptee) {
|
||||
|
|
|
@ -220,9 +220,7 @@ public final class GsonBuilder {
|
|||
* @param fieldNamingStrategy the actual naming strategy to apply to the fields
|
||||
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
||||
* @since 1.3
|
||||
* @deprecated use {@link #setFieldNamingStrategy(FieldNamingStrategy2)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
|
||||
return setFieldNamingStrategy(new FieldNamingStrategy2Adapter(fieldNamingStrategy));
|
||||
}
|
||||
|
@ -233,9 +231,9 @@ public final class GsonBuilder {
|
|||
*
|
||||
* @param fieldNamingStrategy the actual naming strategy to apply to the fields
|
||||
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
||||
* @since 1.4
|
||||
* @since 1.5
|
||||
*/
|
||||
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy2 fieldNamingStrategy) {
|
||||
GsonBuilder setFieldNamingStrategy(FieldNamingStrategy2 fieldNamingStrategy) {
|
||||
this.fieldNamingPolicy =
|
||||
new SerializedNameAnnotationInterceptingNamingPolicy(fieldNamingStrategy);
|
||||
return this;
|
||||
|
@ -434,7 +432,7 @@ public final class GsonBuilder {
|
|||
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
||||
* @since 1.5
|
||||
*/
|
||||
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
|
||||
GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
|
||||
Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|
||||
|| typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?>);
|
||||
if (typeAdapter instanceof InstanceCreator<?>) {
|
||||
|
|
|
@ -42,7 +42,7 @@ import java.util.Collection;
|
|||
*
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class JavaFieldNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
final class JavaFieldNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
|
||||
@Override
|
||||
protected String translateName(String target, Type fieldType, Collection<Annotation> annotations) {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
package com.google.gson;
|
||||
|
||||
/** Token Manager. */
|
||||
class JsonParserJavaccTokenManager implements JsonParserJavaccConstants
|
||||
@SuppressWarnings("all")
|
||||
final class JsonParserJavaccTokenManager implements JsonParserJavaccConstants
|
||||
{
|
||||
|
||||
/** Debug output. */
|
||||
|
|
|
@ -35,7 +35,7 @@ package com.google.gson;
|
|||
*
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class LowerCamelCaseSeparatorNamingPolicy extends CompositionFieldNamingPolicy {
|
||||
final class LowerCamelCaseSeparatorNamingPolicy extends CompositionFieldNamingPolicy {
|
||||
|
||||
public LowerCamelCaseSeparatorNamingPolicy(String separatorString) {
|
||||
super(new CamelCaseSeparatorNamingPolicy(separatorString), new LowerCaseNamingPolicy());
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.Collection;
|
|||
* @author Inderjeet Singh
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class LowerCaseNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
final class LowerCaseNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
|
||||
@Override
|
||||
protected String translateName(String target, Type fieldType,
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Map;
|
|||
* @author Inderjeet Singh
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class LruCache<K, V> extends LinkedHashMap<K, V> implements Cache<K, V> {
|
||||
final class LruCache<K, V> extends LinkedHashMap<K, V> implements Cache<K, V> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int maxCapacity;
|
||||
|
|
|
@ -46,7 +46,7 @@ import java.util.Collection;
|
|||
*
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class ModifyFirstLetterNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
final class ModifyFirstLetterNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
|
||||
public enum LetterModifier {
|
||||
UPPER,
|
||||
|
|
|
@ -36,7 +36,7 @@ package com.google.gson;
|
|||
*
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class UpperCamelCaseSeparatorNamingPolicy extends CompositionFieldNamingPolicy {
|
||||
final class UpperCamelCaseSeparatorNamingPolicy extends CompositionFieldNamingPolicy {
|
||||
|
||||
public UpperCamelCaseSeparatorNamingPolicy(String separatorString) {
|
||||
super(new CamelCaseSeparatorNamingPolicy(separatorString),
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Collection;
|
|||
*
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class UpperCaseNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
final class UpperCaseNamingPolicy extends RecursiveFieldNamingPolicy {
|
||||
|
||||
@Override
|
||||
protected String translateName(String target, Type fieldType, Collection<Annotation> annotations) {
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
|
||||
package com.google.gson.metrics;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
@ -23,13 +30,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Tests to measure performance for Gson. All tests in this file will be disabled in code. To run
|
||||
* them remove disabled_ prefix from the tests and run them.
|
||||
|
@ -147,7 +147,7 @@ public class PerformanceTest extends TestCase {
|
|||
* Created in response to http://code.google.com/p/google-gson/issues/detail?id=96
|
||||
*/
|
||||
// Last I tested, Gson was able to serialize upto 14MB byte array
|
||||
public void disable_testByteArraySerialization() {
|
||||
public void disabled_testByteArraySerialization() {
|
||||
for (int size = 4145152; true; size += 1036288) {
|
||||
byte[] ba = new byte[size];
|
||||
for (int i = 0; i < size; ++i) {
|
||||
|
@ -191,9 +191,9 @@ public class PerformanceTest extends TestCase {
|
|||
// Serialize exposed classes avg time: 159 ms
|
||||
// Deserialized exposed classes avg time: 173 ms
|
||||
|
||||
public void disable_testSerializeClasses() {
|
||||
public void disabled_testSerializeClasses() {
|
||||
ClassWithList c = new ClassWithList("str");
|
||||
for (int i = 0; i < 5000; ++i) {
|
||||
for (int i = 0; i < COLLECTION_SIZE; ++i) {
|
||||
c.list.add(new ClassWithField("element-" + i));
|
||||
}
|
||||
StringWriter w = new StringWriter();
|
||||
|
@ -206,7 +206,7 @@ public class PerformanceTest extends TestCase {
|
|||
System.out.printf("Serialize classes avg time: %d ms\n", avg);
|
||||
}
|
||||
|
||||
public void disable_testDeserializeClasses() {
|
||||
public void disabled_testDeserializeClasses() {
|
||||
String json = buildJsonForClassWithList();
|
||||
ClassWithList[] target = new ClassWithList[NUM_ITERATIONS];
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
@ -236,7 +236,7 @@ public class PerformanceTest extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
public void disable_testSerializeExposedClasses() {
|
||||
public void disabled_testSerializeExposedClasses() {
|
||||
ClassWithListOfObjects c1 = new ClassWithListOfObjects("str");
|
||||
for (int i1 = 0; i1 < COLLECTION_SIZE; ++i1) {
|
||||
c1.list.add(new ClassWithExposedField("element-" + i1));
|
||||
|
@ -252,7 +252,7 @@ public class PerformanceTest extends TestCase {
|
|||
System.out.printf("Serialize exposed classes avg time: %d ms\n", avg);
|
||||
}
|
||||
|
||||
public void disable_testDeserializeExposedClasses() {
|
||||
public void disabled_testDeserializeExposedClasses() {
|
||||
String json = buildJsonForClassWithList();
|
||||
ClassWithListOfObjects[] target = new ClassWithListOfObjects[NUM_ITERATIONS];
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
@ -264,6 +264,18 @@ public class PerformanceTest extends TestCase {
|
|||
System.out.printf("Deserialize exposed classes avg time: %d ms\n", avg);
|
||||
}
|
||||
|
||||
public void disabled_testLargeGsonMapRoundTrip() throws Exception {
|
||||
Map<Long, Long> original = new HashMap<Long, Long>();
|
||||
for (long i = 0; i < 1000000; i++) {
|
||||
original.put(i, i + 1);
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(original);
|
||||
Type longToLong = new TypeToken<Map<Long, Long>>(){}.getType();
|
||||
gson.fromJson(json, longToLong);
|
||||
}
|
||||
|
||||
private String buildJsonForClassWithList() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("field:").append("'str',");
|
||||
|
|
Loading…
Reference in New Issue