Code example for JsonPrimitive

0
	 
	private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
	private static class DateTimeSeri implements JsonSerializer<Date>,JsonDeserializer<Date> {
		public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
			return new JsonPrimitive(format.format(src));
		} 
		public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
			try { 
				return format.parse(json.getAsJsonPrimitive().getAsString());
			} catch (ParseException e) {
				throw new JsonParseException(e.getMessage());
			} 
		} 
	} 
}