Deprecate the old FieldNamingStrategy interface and open up the FieldNamingStrategy2 instead to take its place.

This commit is contained in:
Joel Leitch 2011-01-22 22:27:30 +00:00
parent b883f8f4aa
commit fb7bd7b1b7
3 changed files with 11 additions and 3 deletions

View File

@ -26,7 +26,9 @@ import java.lang.reflect.Field;
* @author Inderjeet Singh * @author Inderjeet Singh
* @author Joel Leitch * @author Joel Leitch
* @since 1.3 * @since 1.3
* @deprecated use the {@link FieldNamingStrategy2} instead
*/ */
@Deprecated
public interface FieldNamingStrategy { public interface FieldNamingStrategy {
/** /**

View File

@ -24,15 +24,16 @@ package com.google.gson;
* *
* @author Inderjeet Singh * @author Inderjeet Singh
* @author Joel Leitch * @author Joel Leitch
*
* @since 1.7
*/ */
interface FieldNamingStrategy2 { public interface FieldNamingStrategy2 {
/** /**
* Translates the field name into its JSON field name representation. * Translates the field name into its JSON field name representation.
* *
* @param f the field that is being translated * @param f the field that is being translated
* @return the translated field name. * @return the translated field name.
* @since 1.3
*/ */
public String translateName(FieldAttributes f); public String translateName(FieldAttributes f);
} }

View File

@ -216,7 +216,11 @@ public final class GsonBuilder {
* @param fieldNamingStrategy the actual naming strategy to apply to the fields * @param fieldNamingStrategy the actual naming strategy to apply to the fields
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3 * @since 1.3
* @deprecated convert {@code fieldNamingStrategy} to a implement from
* {@link FieldNamingStrategy2} and call {@link #setFieldNamingStrategy(FieldNamingStrategy2)}
* instead.
*/ */
@Deprecated
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) { public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
return setFieldNamingStrategy(new FieldNamingStrategy2Adapter(fieldNamingStrategy)); return setFieldNamingStrategy(new FieldNamingStrategy2Adapter(fieldNamingStrategy));
} }
@ -227,8 +231,9 @@ public final class GsonBuilder {
* *
* @param fieldNamingStrategy the actual naming strategy to apply to the fields * @param fieldNamingStrategy the actual naming strategy to apply to the fields
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.7
*/ */
GsonBuilder setFieldNamingStrategy(FieldNamingStrategy2 fieldNamingStrategy) { public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy2 fieldNamingStrategy) {
this.fieldNamingPolicy = this.fieldNamingPolicy =
new SerializedNameAnnotationInterceptingNamingPolicy(fieldNamingStrategy); new SerializedNameAnnotationInterceptingNamingPolicy(fieldNamingStrategy);
return this; return this;