List of usage examples for com.google.gson GsonBuilder setDateFormat
public GsonBuilder setDateFormat(int style)
From source file:com.bing.maps.rest.services.impl.BaseBingMapsApiQuery.java
License:Apache License
/** * Gets the gson builder.//from ww w .ja va 2s. c om * * @return the gson builder */ protected GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); builder.setDateFormat(ApplicationConstants.RFC822DATEFORMAT); builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); builder.registerTypeAdapter(LocationType.class, new JsonDeserializer<LocationType>() { @Override public LocationType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return LocationType.fromValue(arg0.getAsString()); } }); builder.registerTypeAdapter(AddressComponentType.class, new JsonDeserializer<AddressComponentType>() { @Override public AddressComponentType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return AddressComponentType.fromValue(arg0.getAsString()); } }); builder.registerTypeAdapter(TravelMode.class, new JsonDeserializer<TravelMode>() { @Override public TravelMode deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return TravelMode.fromValue(arg0.getAsString()); } }); return builder; }
From source file:com.framework.util.JSONUtil.java
License:Apache License
/** * ????? {@code JSON} ?// w ww. j a v a2s .c o m * <p /> * <strong>???? <code>"{}"</code> ? <code>"[]"</code> * </strong> * * @param target * @param targetType * @param isSerializeNulls ?? {@code null} * @param version ? * @param datePattern ?? * @param excludesFieldsWithoutExpose ? {@literal @Expose} * @return {@code JSON} ? * @since 1.0 */ public static String toJson(Object target, Type targetType, boolean isSerializeNulls, Double version, String datePattern, boolean excludesFieldsWithoutExpose) { if (target == null) return EMPTY_JSON; GsonBuilder builder = new GsonBuilder(); if (isSerializeNulls) builder.serializeNulls(); if (version != null) builder.setVersion(version.doubleValue()); if (Tools.isEmpty(datePattern)) datePattern = DEFAULT_DATE_PATTERN; builder.setDateFormat(datePattern); if (excludesFieldsWithoutExpose) builder.excludeFieldsWithoutExposeAnnotation(); return toJson(target, targetType, builder); }
From source file:com.gelakinetic.mtgfam.helpers.tcgp.JsonObjects.AccessToken.java
License:Open Source License
public static void setDateFormat(GsonBuilder builder) { // Sun, 04 Feb 2018 23:30:02 GMT builder.setDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); }
From source file:com.github.api.v2.services.impl.BaseGitHubService.java
License:Apache License
/** * Gets the gson builder./* w w w . ja v a 2s. c o m*/ * * @return the gson builder */ protected GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); builder.setDateFormat(ApplicationConstants.DATE_FORMAT); builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); builder.setFieldNamingStrategy(new FieldNamingStrategy() { @Override public String translateName(Field field) { if (field.getType().equals(Repository.Visibility.class)) { return "private"; } else if (field.getType().equals(Gist.Visibility.class)) { return "public"; } else { return field.getName(); } } }); builder.registerTypeAdapter(Issue.State.class, new JsonDeserializer<Issue.State>() { @Override public Issue.State deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return Issue.State.fromValue(arg0.getAsString()); } }); builder.registerTypeAdapter(Repository.Visibility.class, new JsonDeserializer<Repository.Visibility>() { @Override public Repository.Visibility deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return (arg0.getAsBoolean()) ? Repository.Visibility.PRIVATE : Repository.Visibility.PUBLIC; } }); builder.registerTypeAdapter(Gist.Visibility.class, new JsonDeserializer<Gist.Visibility>() { @Override public Gist.Visibility deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return (arg0.getAsBoolean()) ? Gist.Visibility.PUBLIC : Gist.Visibility.PRIVATE; } }); builder.registerTypeAdapter(Language.class, new JsonDeserializer<Language>() { @Override public Language deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return Language.fromValue(arg0.getAsString()); } }); builder.registerTypeAdapter(Tree.Type.class, new JsonDeserializer<Tree.Type>() { @Override public Tree.Type deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return Tree.Type.fromValue(arg0.getAsString()); } }); return builder; }
From source file:com.github.api.v2.services.impl.CommitServiceImpl.java
License:Apache License
@Override protected GsonBuilder getGsonBuilder() { GsonBuilder gson = super.getGsonBuilder(); gson.setDateFormat("yyyy-MM-dd'T'HH:mm:ss"); return gson;//from ww w .j a va2 s . c om }
From source file:com.github.api.v2.services.impl.FeedServiceImpl.java
License:Apache License
protected GsonBuilder getGsonBuilder() { GsonBuilder gson = super.getGsonBuilder(); gson.setDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z"); return gson;//ww w. j av a 2 s .c o m }
From source file:com.github.api.v2.services.impl.JobServiceImpl.java
License:Apache License
@Override protected GsonBuilder getGsonBuilder() { GsonBuilder gson = super.getGsonBuilder(); gson.setDateFormat("EEE MMM d HH:mm:ss z yyyy"); return gson;//from ww w. ja va 2s . c om }
From source file:com.github.api.v2.services.impl.NetworkServiceImpl.java
License:Apache License
protected GsonBuilder getGsonBuilder() { GsonBuilder gson = super.getGsonBuilder(); gson.setDateFormat("yyyy-MM-dd HH:mm:ss"); return gson;// w ww.j a v a 2s . c o m }
From source file:com.github.api.v2.services.impl.RepositoryServiceImpl.java
License:Apache License
protected GsonBuilder getGsonBuilder() { GsonBuilder gson = super.getGsonBuilder(); gson.setDateFormat("yyyy-MM-dd'T'HH:mm:ss"); return gson;//w ww . j a va 2s. c om }
From source file:com.google.code.bing.search.client.impl.BingSearchJsonClientImpl.java
License:Apache License
/** * Gets the gson builder./*w w w . ja v a 2 s .c o m*/ * * @return the gson builder */ protected GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); builder.setDateFormat(ApplicationConstants.DATE_FORMAT); builder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE); // builder.registerTypeAdapter(Issue.State.class, new JsonDeserializer<Issue.State>() { // @Override // public Issue.State deserialize(JsonElement arg0, Type arg1, // JsonDeserializationContext arg2) throws JsonParseException { // return Issue.State.fromValue(arg0.getAsString()); // } // }); return builder; }