use of com.google.gson.GsonBuilder in project ninja by ninjaframework.
the class ApiControllerDocTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// 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>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
use of com.google.gson.GsonBuilder in project ninja by ninjaframework.
the class ApiControllerDocTesterTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// 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>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
use of com.google.gson.GsonBuilder in project ninja by ninjaframework.
the class ApiControllerTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// 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>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
use of com.google.gson.GsonBuilder in project kickmaterial by byoutline.
the class GlobalModule method providesGson.
@Provides
Gson providesGson() {
GsonBuilder builder = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
JsonDeserializer<DateTime> deserializer = (json, typeOfT, context) -> new DateTime(json.getAsJsonPrimitive().getAsLong() * 1000);
builder.registerTypeAdapter(DateTime.class, deserializer);
return builder.create();
}
use of com.google.gson.GsonBuilder in project jphp by jphp-compiler.
the class JsonExtension method createGsonBuilderForDecode.
public static GsonBuilder createGsonBuilderForDecode(MemoryDeserializer memoryDeserializer) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Memory.class, memoryDeserializer);
return builder;
}
Aggregations