congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
GsonBuilder.setFieldNamingStrategy
Code IndexAdd Tabnine to your IDE (free)

How to use
setFieldNamingStrategy
method
in
com.google.gson.GsonBuilder

Best Java code snippets using com.google.gson.GsonBuilder.setFieldNamingStrategy (Showing top 16 results out of 315)

origin: stackoverflow.com

gsonBuilder.setFieldNamingStrategy(new MyFieldNamingStrategy());
Gson gson = gsonBuilder.create();
Egg egg = gson.fromJson(new FileReader("input.json"), Egg.class);
origin: rharter/auto-value-gson

public void testCustomFieldNamingStrategy() {
  Gson gson = new GsonBuilder()
      .setFieldNamingStrategy(new xPrefixStrategy())
      .registerTypeAdapterFactory(SampleAdapterFactory.create())
      .create();
  assertEquals("{'xlowerCamel':1,'xUpperCamel':2,'x_lowerCamelLeadingUnderscore':3," +
          "'x_UpperCamelLeadingUnderscore':4,'xlower_words':5,'xUPPER_WORDS':6," +
          "'annotatedName':7,'xlowerId':8}",
      gson.toJson(getTestNames()).replace('\"', '\''));
}
origin: shazam/shazamcrest

private static void markSetAndMapFields(final GsonBuilder gsonBuilder) {
  gsonBuilder.setFieldNamingStrategy(new FieldNamingStrategy() {
    @Override
    public String translateName(Field f) {
      if (Set.class.isAssignableFrom(f.getType()) || Map.class.isAssignableFrom(f.getType())) {
        return MARKER + f.getName();
      }
      return f.getName();
    }
  });
}
origin: com.shazam/shazamcrest

private static void markSetAndMapFields(final GsonBuilder gsonBuilder) {
  gsonBuilder.setFieldNamingStrategy(new FieldNamingStrategy() {
    @Override
    public String translateName(Field f) {
      if (Set.class.isAssignableFrom(f.getType()) || Map.class.isAssignableFrom(f.getType())) {
        return MARKER + f.getName();
      }
      return f.getName();
    }
  });
}
origin: stackoverflow.com

 GsonBuilder gsonBuilder = new GsonBuilder();
sonBuilder.addSerializationExclusionStrategy(new PersonFromDExclusionStrategy());
gsonBuilder.setFieldNamingStrategy(new PersonFromDBNamingStrategy());
Gson gson = gsonBuilder.create();

PersonFromDB1 person1 = ...; // get the object
PersonFromDB2 person2 = ...; // get the object

System.out.println(gson.toJson(person1));
System.out.println(gson.toJson(person2));
origin: eatnumber1/google-gson

/**
 * Configures Gson to apply a specific naming policy strategy to an object's field during
 * serialization and deserialization.
 *
 * @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
 */
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
 return setFieldNamingStrategy(new FieldNamingStrategy2Adapter(fieldNamingStrategy));
}
origin: eatnumber1/google-gson

/**
 * Configures Gson to apply a specific naming policy to an object's field during serialization
 * and deserialization.
 *
 * @param namingConvention the JSON field naming convention to use for serialization and
 * deserialization.
 * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
 */
public GsonBuilder setFieldNamingPolicy(FieldNamingPolicy namingConvention) {
 return setFieldNamingStrategy(namingConvention.getFieldNamingPolicy());
}
origin: AEFeinstein/mtg-familiar

private static Gson getGson() {
  GsonBuilder reader = new GsonBuilder();
  reader.setFieldNamingStrategy((new PrefixedFieldNamingStrategy("m")));
  reader.disableHtmlEscaping();
  reader.setPrettyPrinting();
  return reader.create();
}
origin: zhao-mingjian/qvod

private Gson getGson() {
  if (gson == null) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingStrategy(new AnnotateNaming());
    gsonBuilder.serializeNulls();
    gsonBuilder.excludeFieldsWithModifiers(Modifier.TRANSIENT);
    gson = gsonBuilder.create();
  }
  return gson;
}
origin: yangchong211/YCAudioPlayer

/**
 * 第一种方式
 * @return              Gson对象
 */
public static Gson getJson() {
  if (gson == null) {
    GsonBuilder builder = new GsonBuilder();
    builder.setLenient();
    builder.setFieldNamingStrategy(new AnnotateNaming());
    builder.serializeNulls();
    gson = builder.create();
  }
  return gson;
}
origin: org.apache.camel/camel-gson

@Override
protected void doStart() throws Exception {
  if (gson == null) {
    GsonBuilder builder = new GsonBuilder();
    if (exclusionStrategies != null && !exclusionStrategies.isEmpty()) {
      ExclusionStrategy[] strategies = exclusionStrategies.toArray(new ExclusionStrategy[exclusionStrategies.size()]);
      builder.setExclusionStrategies(strategies);
    }
    if (longSerializationPolicy != null) {
      builder.setLongSerializationPolicy(longSerializationPolicy);
    }
    if (fieldNamingPolicy != null) {
      builder.setFieldNamingPolicy(fieldNamingPolicy);
    }
    if (fieldNamingStrategy != null) {
      builder.setFieldNamingStrategy(fieldNamingStrategy);
    }
    if (serializeNulls) {
      builder.serializeNulls();
    }
    if (prettyPrint) {
      builder.setPrettyPrinting();
    }
    if (dateFormatPattern != null) {
      builder.setDateFormat(dateFormatPattern);
    }
    gson = builder.create();
  }
}
origin: leangen/graphql-spqr

private GsonBuilder initBuilder(Map<Class, List<Class<?>>> concreteSubTypes, GlobalEnvironment environment) {
  GsonBuilder gsonBuilder = (prototype != null ? prototype.newBuilder() : new GsonBuilder())
      .serializeNulls()
      .setFieldNamingStrategy(fieldNamingStrategy != null ? fieldNamingStrategy : new GsonFieldNamingStrategy(environment.messageBundle))
      .registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory());
  return configurers.stream().reduce(gsonBuilder, (builder, config) ->
          config.configure(new ConfigurerParams(builder, concreteSubTypes, this.typeInfoGenerator, environment)), (b1, b2) -> b2);
}
origin: com.sap.cloud.servicesdk/odatav2-connectivity

  public static GsonBuilder newGsonBuilder()
  {
    return new GsonBuilder()
      .disableHtmlEscaping()
      .setFieldNamingStrategy(new ElementNameGsonFieldNamingStrategy())
      .setExclusionStrategies(new AnnotatedFieldGsonExclusionStrategy<>(ElementName.class))
      .registerTypeAdapterFactory(new StringConstructedTypeAdapterFactory())
      .registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
      .registerTypeAdapter(Calendar.class, new CalenderTypeAdapter())
      .registerTypeAdapter(Date.class, new DateTypeAdapter())
      .registerTypeAdapter(Long.class, new LongTypeAdapter());
  }
}
origin: whiskeyfei/Gson-Review

@Test
public void TestSerializationCustomGson() {
  FieldNamingStrategy customPolicy = new FieldNamingStrategy() {
    @Override
    public String translateName(Field f) {
      return f.getName().replace("_", "");
    }
  };
  GsonBuilder gsonBuilder = new GsonBuilder();
  gsonBuilder.setFieldNamingStrategy(customPolicy);
  Gson gson = gsonBuilder.create();
  UserNaming user = new UserNaming("Norman", "norman@futurestud.io", true, 26);
  String usersJson = gson.toJson(user);
  System.out.println("usersJson:" + usersJson);
}
origin: zccodere/study-imooc

gsonBuilder.setFieldNamingStrategy(new FieldNamingStrategy() {
  @Override
  public String translateName(Field f) {
origin: zccodere/study-imooc

gsonBuilder.setFieldNamingStrategy(new FieldNamingStrategy() {
  @Override
  public String translateName(Field f) {
com.google.gsonGsonBuildersetFieldNamingStrategy

Javadoc

Configures Gson to apply a specific naming policy strategy to an object's field during serialization and deserialization.

Popular methods of GsonBuilder

  • create
    Creates a Gson instance based on the current configuration. This method is free of side-effects to t
  • <init>
    Creates a GsonBuilder instance that can be used to build Gson with various configuration settings. G
  • registerTypeAdapter
    Configures Gson for custom serialization or deserialization. This method combines the registration o
  • setPrettyPrinting
    Configures Gson to output Json that fits in a page for pretty printing. This option only affects Jso
  • serializeNulls
    Configure Gson to serialize null fields. By default, Gson omits all fields that are null during seri
  • disableHtmlEscaping
    By default, Gson escapes HTML characters such as < > etc. Use this option to configure Gson to pass-
  • setDateFormat
    Configures Gson to serialize Date objects according to the pattern provided. You can call this metho
  • registerTypeAdapterFactory
    Register a factory for type adapters. Registering a factory is useful when the type adapter needs to
  • setFieldNamingPolicy
    Configures Gson to apply a specific naming policy to an object's field during serialization and dese
  • registerTypeHierarchyAdapter
    Configures Gson for custom serialization or deserialization for an inheritance type hierarchy. This
  • excludeFieldsWithoutExposeAnnotation
    Configures Gson to exclude all fields from consideration for serialization or deserialization that d
  • setExclusionStrategies
    Configures Gson to apply a set of exclusion strategies during both serialization and deserialization
  • excludeFieldsWithoutExposeAnnotation,
  • setExclusionStrategies,
  • enableComplexMapKeySerialization,
  • setLenient,
  • addSerializationExclusionStrategy,
  • excludeFieldsWithModifiers,
  • serializeSpecialFloatingPointValues,
  • setVersion,
  • addTypeAdaptersForDate

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • getSystemService (Context)
  • getContentResolver (Context)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • JFrame (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now