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

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

Best Java code snippets using com.google.gson.GsonBuilder.setDateFormat (Showing top 20 results out of 963)

origin: SonarSource/sonarqube

public static Gson create() {
 return new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").setPrettyPrinting().create();
}
origin: stackoverflow.com

 public <T> T deserialize(String jsonString, Class<T> clazz) {
  GsonBuilder builder = new GsonBuilder();
  builder.setDateFormat("MM/dd/yy HH:mm:ss");

  Gson gson = builder.create();
  return gson.fromJson(jsonString, clazz);
}
origin: spring-projects/spring-framework

@Override
public void afterPropertiesSet() {
  GsonBuilder builder = (this.base64EncodeByteArrays ?
      GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
  if (this.serializeNulls) {
    builder.serializeNulls();
  }
  if (this.prettyPrinting) {
    builder.setPrettyPrinting();
  }
  if (this.disableHtmlEscaping) {
    builder.disableHtmlEscaping();
  }
  if (this.dateFormatPattern != null) {
    builder.setDateFormat(this.dateFormatPattern);
  }
  this.gson = builder.create();
}
origin: ctripcorp/apollo

private ApolloOpenApiClient(String portalUrl, String token, RequestConfig requestConfig) {
 this.portalUrl = portalUrl;
 this.token = token;
 CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(requestConfig)
   .setDefaultHeaders(Lists.newArrayList(new BasicHeader("Authorization", token))).build();
 Gson gson = new GsonBuilder().setDateFormat(ApolloOpenApiConstants.JSON_DATE_FORMAT).create();
 String baseUrl = this.portalUrl + ApolloOpenApiConstants.OPEN_API_V1_PREFIX;
 appService = new AppOpenApiService(client, baseUrl, gson);
 namespaceService = new NamespaceOpenApiService(client, baseUrl, gson);
 itemService = new ItemOpenApiService(client, baseUrl, gson);
 releaseService = new ReleaseOpenApiService(client, baseUrl, gson);
}
origin: ctripcorp/apollo

 @Bean
 public HttpMessageConverters messageConverters() {
  GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
  gsonHttpMessageConverter.setGson(
      new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
  final List<HttpMessageConverter<?>> converters = Lists.newArrayList(
      new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
      new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
  return new HttpMessageConverters() {
   @Override
   public List<HttpMessageConverter<?>> getConverters() {
    return converters;
   }
  };
 }
}
origin: commonsguy/cw-omnibus

@Override
public void onResponse(Response response) throws IOException {
 Gson gson=new GsonBuilder()
  .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
  .create();
 Type listType=new TypeToken<List<BackupMetadata>>() {}.getType();
 EventBus
  .getDefault()
  .post(
   gson.fromJson(response.body().charStream(), listType));
}
origin: org.springframework/spring-web

@Override
public void afterPropertiesSet() {
  GsonBuilder builder = (this.base64EncodeByteArrays ?
      GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
  if (this.serializeNulls) {
    builder.serializeNulls();
  }
  if (this.prettyPrinting) {
    builder.setPrettyPrinting();
  }
  if (this.disableHtmlEscaping) {
    builder.disableHtmlEscaping();
  }
  if (this.dateFormatPattern != null) {
    builder.setDateFormat(this.dateFormatPattern);
  }
  this.gson = builder.create();
}
origin: north2016/T-MVP

private Api() {
  HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
  logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
  Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb
  OkHttpClient okHttpClient = new OkHttpClient.Builder()
      .readTimeout(7676, TimeUnit.MILLISECONDS)
      .connectTimeout(7676, TimeUnit.MILLISECONDS)
      .addInterceptor(headInterceptor)
      .addInterceptor(logInterceptor)
      .addNetworkInterceptor(new HttpCacheInterceptor())
      .cache(cache)
      .build();
  Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();
  retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create(gson))
      .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
      .baseUrl(C.BASE_URL)
      .build();
  service = retrofit.create(ApiService.class);
}
origin: jaydenxiao2016/AndroidFire

    .build();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();
retrofit = new Retrofit.Builder()
    .client(okHttpClient)
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create();
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create();
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create();
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create();
origin: ribot/ribot-app-android

@Inject
public PreferencesHelper(@ApplicationContext Context context) {
  mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
  mGson = new GsonBuilder()
      .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz")
      .create();
}
origin: ribot/ribot-app-android

public static RibotService makeRibotService(Context context) {
  HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
  logging.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY
      : HttpLoggingInterceptor.Level.NONE);
  OkHttpClient okHttpClient = new OkHttpClient.Builder()
      .addInterceptor(new UnauthorisedInterceptor(context))
      .addInterceptor(logging)
      .build();
  Gson gson = new GsonBuilder()
      .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
      .create();
  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(RibotService.ENDPOINT)
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create(gson))
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .build();
  return retrofit.create(RibotService.class);
}
origin: WangDaYeeeeee/Mysplash

private CollectionNodeApi buildApi(OkHttpClient client) {
  return new Retrofit.Builder()
      .baseUrl(Mysplash.UNSPLASH_URL)
      .client(client)
      .addConverterFactory(
          GsonConverterFactory.create(
              new GsonBuilder()
                  .setDateFormat(Mysplash.DATE_FORMAT)
                  .create()))
      .build()
      .create((CollectionNodeApi.class));
}
origin: WangDaYeeeeee/Mysplash

private PhotoNodeApi buildApi(OkHttpClient client) {
  return new Retrofit.Builder()
      .baseUrl(Mysplash.UNSPLASH_URL)
      .client(client)
      .addConverterFactory(
          GsonConverterFactory.create(
              new GsonBuilder()
                  .setDateFormat(Mysplash.DATE_FORMAT)
                  .create()))
      .build()
      .create((PhotoNodeApi.class));
}
origin: WangDaYeeeeee/Mysplash

private SearchNodeApi buildApi(OkHttpClient client) {
  return new Retrofit.Builder()
      .baseUrl(Mysplash.UNSPLASH_URL)
      .client(client)
      .addConverterFactory(
          GsonConverterFactory.create(
              new GsonBuilder()
                  .setDateFormat(Mysplash.DATE_FORMAT)
                  .create()))
      .build()
      .create((SearchNodeApi.class));
}
origin: burgessjp/GanHuoIO

private ServiceFactory() {
  mGson = new GsonBuilder()
      .setDateFormat("yyyy-MM-dd hh:mm:ss")
      .create();
  mOkHttpClient = OkHttpProvider.getDefaultOkHttpClient();
}
origin: javers/javers

public JsonConverter build() {
  registerJsonTypeAdapters(UtilTypeCoreAdapters.adapters());
  registerJsonTypeAdapters(Java8TypeAdapters.adapters());
  registerJsonTypeAdapter(new AtomicTypeAdapter(typeSafeValues));
  if (prettyPrint){
    gsonBuilder.setPrettyPrinting();
  }
  gsonBuilder.enableComplexMapKeySerialization();
  gsonBuilder.serializeNulls()
        .setDateFormat(ISO_DATE_TIME_FORMAT);
  return new JsonConverter(gsonBuilder.create());
}
com.google.gsonGsonBuildersetDateFormat

Javadoc

Configures Gson to to serialize Date objects according to the style value provided. You can call this method or #setDateFormat(String) multiple times, but only the last invocation will be used to decide the serialization format.

Note that this style value should be one of the predefined constants in the DateFormat class. See the documentation in java.text.DateFormat for more information on the valid style constants.

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-
  • 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

  • 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)
  • CodeWhisperer alternatives
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