@Test
public void testDefaultDateFormats() throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy");
Person charlie = new Person("Charlie", "Hubbard", new Date(), null, null);
charlie.setBirthdate(df.parse("03/21/76"));
DateTransformer transformer = new DateTransformer( df.toPattern() );
String json = new JSONSerializer().transform(transformer, "birthdate").serialize(charlie);
Person newUser = new JSONDeserializer<Person>().deserialize(json);
assertEquals( charlie.getBirthdate(), newUser.getBirthdate() );
assertEquals( "03/21/76", df.format(newUser.getBirthdate()) );
String pattern = "yyyy-MM-dd hh:mm:ss";
json = new JSONSerializer().transform( new DateTransformer( pattern ), Date.class ).serialize(charlie);
Person user = new JSONDeserializer<Person>().use("birthdate", new DateObjectFactory().add(pattern) ).deserialize(json);
assertEquals( charlie.getBirthdate(), user.getBirthdate() );
assertEquals( "03/21/76", df.format( user.getBirthdate() ) );
DateObjectFactory.addDefaultFormat( pattern );
json = new JSONSerializer().transform( new DateTransformer( pattern ), Date.class ).serialize(charlie);
user = new JSONDeserializer<Person>().deserialize(json);
assertEquals( charlie.getBirthdate(), user.getBirthdate() );
assertEquals( "03/21/76", df.format( user.getBirthdate() ) );
}