当前位置: 首页>>代码示例>>Java>>正文


Java GsonBuilder.setDateFormat方法代码示例

本文整理汇总了Java中com.google.gson.GsonBuilder.setDateFormat方法的典型用法代码示例。如果您正苦于以下问题:Java GsonBuilder.setDateFormat方法的具体用法?Java GsonBuilder.setDateFormat怎么用?Java GsonBuilder.setDateFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.GsonBuilder的用法示例。


在下文中一共展示了GsonBuilder.setDateFormat方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: EventServlet

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public EventServlet(LeshanServer server, int securePort) {
    server.getRegistrationService().addListener(this.registrationListener);
    server.getObservationService().addListener(this.observationListener);

    // add an interceptor to each endpoint to trace all CoAP messages
    coapMessageTracer = new CoapMessageTracer(server.getRegistrationService());
    for (Endpoint endpoint : server.getCoapServer().getEndpoints()) {
        endpoint.addInterceptor(coapMessageTracer);
    }

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeHierarchyAdapter(Registration.class, new RegistrationSerializer(securePort));
    gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
    gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    this.gson = gsonBuilder.create();
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:17,代码来源:EventServlet.java

示例2: getGsonBuilder

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
 * 构建通用GsonBuilder, 封装初始化工作
 *
 * @return
 */
public static GsonBuilder getGsonBuilder(boolean prettyPrinting) {
	GsonBuilder gb = new GsonBuilder();
	gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss");
	gb.setExclusionStrategies(new ExclusionStrategy() {
		@Override
		public boolean shouldSkipField(FieldAttributes f) {
			return f.getAnnotation(WJsonExclued.class) != null;
		}

		@Override
		public boolean shouldSkipClass(Class<?> clazz) {
			return clazz.getAnnotation(WJsonExclued.class) != null;
		}
	});
	if (prettyPrinting)
		gb.setPrettyPrinting();
	return gb;
}
 
开发者ID:DataAgg,项目名称:DaUtil,代码行数:24,代码来源:WJsonUtils.java

示例3: writeTo

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
@Override
public void writeTo(Representation rep, Class<?> type, Type genericType,
        Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, Object> httpHeaders,
        OutputStream entityStream) throws IOException,
        WebApplicationException {

    try (OutputStreamWriter writer = new OutputStreamWriter(entityStream,
            CommonParams.CHARSET)) {
        GsonBuilder builder = new GsonBuilder();
        builder.setDateFormat(CommonParams.FORMAT_DATE);

        if (rep.getVersion() != null) {
            builder.setVersion(rep.getVersion());
        }

        Gson gson = builder.create();
        gson.toJson(rep, genericType, writer);

    } catch (JsonSyntaxException e) {
        throw WebException.internalServerError()
                .message(CommonParams.ERROR_JSON_FORMAT).build();
    }

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:GsonMessageProvider.java

示例4: createGson

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static Gson createGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    //gsonBuilder.setExclusionStrategies(new SpecificClassExclusionStrategy(null, Model.class));
    gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss");

    JsonDeserializer deserializer = new IntegerJsonDeserializer();
    gsonBuilder.registerTypeAdapter(int.class, deserializer);
    gsonBuilder.registerTypeAdapter(Integer.class, deserializer);

    deserializer = new FloatJsonDeserializer();
    gsonBuilder.registerTypeAdapter(float.class, deserializer);
    gsonBuilder.registerTypeAdapter(Float.class, deserializer);

    deserializer = new DoubleJsonDeserializer();
    gsonBuilder.registerTypeAdapter(double.class, deserializer);
    gsonBuilder.registerTypeAdapter(Double.class, deserializer);

    deserializer = new StringJsonDeserializer();
    gsonBuilder.registerTypeAdapter(String.class, deserializer);

    gsonBuilder.registerTypeAdapter(Tweet.Image.class, new ImageJsonDeserializer());

    return gsonBuilder.create();
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:25,代码来源:AppOperator.java

示例5: toJson

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static String toJson(Object object) {
    if (gson == null) {
        GsonBuilder builder = new GsonBuilder();
        builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
        gson = builder.create();
    }
    String json = gson.toJson(object);
    return json;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:10,代码来源:JsonUtils.java

示例6: jsonToBean

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static <T> T jsonToBean(String json, Class<T> class1) {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
    Gson gson = builder.create();
    T t = gson.fromJson(json, class1);
    return t;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:8,代码来源:JsonUtils.java

示例7: ClientServlet

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public ClientServlet(LwM2mServer server, int securePort) {
    this.server = server;

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeHierarchyAdapter(Registration.class, new RegistrationSerializer(securePort));
    gsonBuilder.registerTypeHierarchyAdapter(LwM2mResponse.class, new ResponseSerializer());
    gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
    gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeDeserializer());
    gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    this.gson = gsonBuilder.create();
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:12,代码来源:ClientServlet.java

示例8: DataSerializer

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public DataSerializer(Class<?> clazz) {
    this.clazz = clazz;

    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(FORMAT_DATE);
    this.gson = builder.create();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:8,代码来源:DataSerializer.java

示例9: buildGson

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static Gson buildGson() {
    // Creates the json object which will manage the information received
    GsonBuilder builder = new GsonBuilder();

    builder.setDateFormat(DateUtils.SERVER_DATE_TIME_PATTERN);
    // 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());
        }
    });
    return builder.create();
}
 
开发者ID:sayemkcn,项目名称:ael,代码行数:14,代码来源:Commons.java

示例10: toArrayList

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public ArrayList<T> toArrayList(String jsonString, Class<T> clazz) {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("dd/MM/yy HH:mm:ss");
    Gson gson = builder.create();
    ListParameterizedType type = new ListParameterizedType(clazz);
    ArrayList list = (ArrayList)gson.fromJson(jsonString, type);
    return list;
}
 
开发者ID:MarioDeAraujoCarvalho,项目名称:FlyHttp,代码行数:9,代码来源:ConverterJSONToArray.java

示例11: create

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static final Gson create(boolean pretty) {
	GsonBuilder builder = new GsonBuilder();
	builder.serializeNulls();
	builder.disableHtmlEscaping();

	// Install MongoDB / BSON serializers
	tryToAddSerializers("io.datatree.dom.adapters.JsonGsonBsonSerializers", builder);

	// Install serializers for Apache Cassandra
	addSerializer(builder, InetAddress.class, (value) -> {
		return new JsonPrimitive(value.getCanonicalHostName());
	});
	addSerializer(builder, Inet4Address.class, (value) -> {
		return new JsonPrimitive(value.getCanonicalHostName());
	});
	addSerializer(builder, Inet6Address.class, (value) -> {
		return new JsonPrimitive(value.getCanonicalHostName());
	});

	// Date serializer
	if (Config.USE_TIMESTAMPS) {
		builder.setDateFormat(Config.TIMESTAMP_FORMAT);
	} else {

		// Milliseconds since epoch Jan 1 , 1970 00:00:00 UTC
		addSerializer(builder, Date.class, (value) -> {
			return new JsonPrimitive(value.getTime());
		});
	}

	// BASE64 serializer
	addSerializer(builder, byte[].class, (value) -> {
		return new JsonPrimitive(BASE64.encode(value));
	});

	// Pretty printing
	if (pretty) {
		builder.setPrettyPrinting();
	}
	return builder.create();
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:42,代码来源:JsonGson.java


注:本文中的com.google.gson.GsonBuilder.setDateFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。