Skip to content

Instantly share code, notes, and snippets.

@collinvandyck
Created September 12, 2012 19:20
Show Gist options
  • Select an option

  • Save collinvandyck/3709237 to your computer and use it in GitHub Desktop.

Select an option

Save collinvandyck/3709237 to your computer and use it in GitHub Desktop.
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class User {
private static final DateFormat ISO_8601_FORMATTER = new ISO8601DateFormat();
public static String dateToISO8601Format(Date date) {
if (date == null) {
return null;
}
return ISO_8601_FORMATTER.format(date);
}
private String id;
private String email;
@JsonIgnore private Date createdAt;
@JsonIgnore private Date updatedAt;
private String name;
private boolean admin;
@JsonIgnore private boolean active;
public User(String id, String email, Date createdAt, Date updatedAt, String name, boolean admin, boolean active) {
this.id = id;
this.email = email;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.name = name;
this.admin = admin;
this.active = active;
}
// getter methods elided for readability.
@JsonProperty("created_at")
public String getCreatedAtISO8601() {
return dateToISO8601Format(getCreatedAt());
}
@JsonProperty("updated_at")
public String getUpdatedAtISO8601() {
return dateToISO8601Format(getUpdatedAt());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment