Code example for JsonPrimitive

0
    sdf.setTimeZone(SharedDateUtil.SWEDISH_TIMEZONE);
  } 
 
  @Override 
  public JsonElement serialize(final Calendar calendar, final Type type, final JsonSerializationContext context) {
    return new JsonPrimitive(sdf.format(calendar.getTime()));
  } 
 
  @Override 
  public Calendar deserialize(final JsonElement element, final Type type, final JsonDeserializationContext context)
      throws JsonParseException { 
 
    String string = element.getAsString();
    Date date;
    try { 
      date = sdf.parse(string);
    } catch (ParseException e) {
      throw new JsonParseException("Kunde inte tolka tid: " + string);
    }