Tabnine Logo
GsonBuilder.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
com.google.gson.GsonBuilder
constructor

Best Java code snippets using com.google.gson.GsonBuilder.<init> (Showing top 20 results out of 9,216)

Refine searchRefine arrow

  • GsonBuilder.create
  • Gson.fromJson
  • Gson.toJson
  • GsonBuilder.registerTypeAdapter
  • PrintStream.println
  • GsonBuilder.disableHtmlEscaping
  • GsonBuilder.setPrettyPrinting
origin: gocd/gocd

@Override
public String requestMessageForNotifyPluginSettingsChange(Map<String, String> pluginSettings) {
  return new GsonBuilder().create().toJson(pluginSettings);
}
origin: gocd/gocd

private ResponseScratch parseResponseForMigration(String responseBody) {
  return new GsonBuilder().create().fromJson(responseBody, ResponseScratch.class);
}
origin: stackoverflow.com

 Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(uglyJSONString);
String prettyJsonString = gson.toJson(je);
origin: alibaba/jstorm

public static String toPrettyJsonString(Object obj) {
  Gson gson2 = new GsonBuilder().setPrettyPrinting().create();
  return gson2.toJson(obj);
}
origin: stackoverflow.com

Gson gson = new GsonBuilder()
   .setExclusionStrategies(new TestExclStrat("in.naishe.test.Country.name"))
   //.serializeNulls()
   .create();
 Student src = new Student();
 String json = gson.toJson(src);
 System.out.println(json);
origin: stackoverflow.com

Gson gson=  new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
 String date = "\"2013-02-10T13:45:30+0100\"";
 Date test = gson.fromJson(date, Date.class);
 System.out.println("date:" + test);
origin: stackoverflow.com

Person p = new Person(1, "Joe", new Person(2, "Mike"));
 com.google.gson.Gson gson = new GsonBuilder().registerTypeAdapter(Person.class, new PersonSerializer())
     .create();
 System.out.println(gson.toJson(p));
origin: square/retrofit

com.google.gson.Gson gson = new GsonBuilder().create();
MoshiConverterFactory moshiConverterFactory = MoshiConverterFactory.create(moshi);
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
System.out.println("Library 1: " + library1.name);
System.out.println("Library 2: " + library2.name);
System.out.println("Library 3: " + library3.name);
origin: stackoverflow.com

 GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Object.class, new NaturalDeserializer());
Gson gson = gsonBuilder.create();
origin: robolectric/robolectric

public JavadocJsonGenerator(
  RobolectricModel model, ProcessingEnvironment environment, File jsonDocsDir) {
 super();
 this.model = model;
 this.messager = environment.getMessager();
 gson = new GsonBuilder()
   .setPrettyPrinting()
   .create();
 this.jsonDocsDir = jsonDocsDir;
}
origin: stackoverflow.com

 GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(CityList.class, new CityListDeserializer());
Gson gson = builder.setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES).create();
CityList list = gson.fromJson(json, CityList.class);
origin: apache/flume

public JSONHandler() {
 gson = new GsonBuilder().disableHtmlEscaping().create();
}
origin: stackoverflow.com

 // Creates the json object which will manage the information received 
GsonBuilder builder = new GsonBuilder(); 

// Register an adapter to manage the date types as long values 
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { 
  public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
   return new Date(json.getAsJsonPrimitive().getAsLong()); 
  } 
});

Gson gson = builder.create();
origin: stackoverflow.com

 Map<String, String> myMap = new HashMap<String, String>();
myMap.put("one", "hello");
myMap.put("two", "world");

Gson gson = new GsonBuilder().create();
String json = gson.toJson(myMap);

System.out.println(json);

Type typeOfHashMap = new TypeToken<Map<String, String>>() { }.getType();
Map<String, String> newMap = gson.fromJson(json, typeOfHashMap); // This type must match TypeToken
System.out.println(newMap.get("one"));
System.out.println(newMap.get("two"));
origin: stackoverflow.com

Gson gson = new GsonBuilder()
   .setExclusionStrategies(new TestExclStrat())
   //.serializeNulls() <-- uncomment to serialize NULL fields as well
   .create();
 Student src = new Student();
 String json = gson.toJson(src);
 System.out.println(json);
origin: stackoverflow.com

 public class GsonTest
{
  public static void main(String[] args)
  {
    // Note the time zone format tweak (removed the ':')
    String json = "[{\"2011-04-30T00:00:00-0700\":100}, {\"2011-04-29T00:00:00-0700\":200}]";

    Gson gson =
      new GsonBuilder()
      .registerTypeAdapter(MyCustomClass.class, new MyCustomDeserializer())
      .create();
    Type collectionType = new TypeToken<Collection<MyCustomClass>>(){}.getType();
    Collection<MyCustomClass> myCustomClasses = gson.fromJson(json, collectionType);
    System.out.println(myCustomClasses);
  }
}
origin: gocd/gocd

private ResponseScratch parseResponseForMigration(String responseBody) {
  return new GsonBuilder().create().fromJson(responseBody, ResponseScratch.class);
}
origin: SonarSource/sonarqube

private static String toJson(Map<String, String> map) {
 Gson gson = new GsonBuilder().create();
 try {
  return encode(gson.toJson(map), UTF_8.name());
 } catch (UnsupportedEncodingException e) {
  throw new IllegalStateException(e);
 }
}
origin: MovingBlocks/Terasology

public GLSLShaderFormat() {
  gson = new GsonBuilder()
      .registerTypeAdapter(ShaderMetadata.class, new ShaderMetadataHandler())
      .create();
}
origin: runelite/runelite

public ObjectExporter(ObjectDefinition object)
{
  this.object = object;
  GsonBuilder builder = new GsonBuilder()
    .setPrettyPrinting();
  gson = builder.create();
}
com.google.gsonGsonBuilder<init>

Javadoc

Creates a GsonBuilder instance that can be used to build Gson with various configuration settings. GsonBuilder follows the builder pattern, and it is typically used by first invoking various configuration methods to set desired options, and finally calling #create().

Popular methods of GsonBuilder

  • create
    Creates a Gson instance based on the current configuration. This method is free of side-effects to t
  • 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
  • enableComplexMapKeySerialization
    Enabling this feature will only change the serialized form if the map key is a complex type (i.e. no
  • setExclusionStrategies,
  • enableComplexMapKeySerialization,
  • setLenient,
  • addSerializationExclusionStrategy,
  • excludeFieldsWithModifiers,
  • serializeSpecialFloatingPointValues,
  • setVersion,
  • setFieldNamingStrategy,
  • addTypeAdaptersForDate

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • setRequestProperty (URLConnection)
  • getSupportFragmentManager (FragmentActivity)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top plugins for Android Studio
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