I added support for timezone, locale, UUID, URL, URI, File and Path.
/**
*
* @author l man
*/
publicstaticclassSample
implementsSerializable{
privatestaticfinallongserialVersionUID=1L;
privateURLurl;
privateURIuri;
privateFilefile;
privateDatedate;
privatefinalUUIDpersistId;
privatePathpath;
privateLocalelocale;
privateTimeZonetimeZone;
privatestaticfinalAtomicLongFieldUpdater<Sample>EFFECTIVEDATE_UPDATER
=AtomicLongFieldUpdater.newUpdater(Sample.class,"effectiveDate");
publicSample(){
this.persistId=UUID.randomUUID();
this.effectiveDate=System.currentTimeMillis();
try{
url=newURL("http://www.google.com");
}catch(MalformedURLExceptione){
e.printStackTrace();
}
try{
uri=newURI("http://www.google.com");
}catch(URISyntaxExceptione){
e.printStackTrace();
}
file=newFile("/usr/local/bin/vertx");
date=newDate();
path=file.toPath();
locale=Locale.CANADA;
timeZone=TimeZone.getTimeZone("PST");
}
publicUUIDgetPersistId(){
returnpersistId;
}
privatevolatilelongeffectiveDate;
publicfinallonggetEffectiveDate(){
returneffectiveDate;
}
publicfinalvoidsetEffectiveDate(longeffectiveDate){
EFFECTIVEDATE_UPDATER.compareAndSet(this,this.effectiveDate,effectiveDate);
}
...
@Test
publicvoidtest4(){
Samplesample1=newSample();
Stringjson=JsonFactory.toJson(sample1);
puts(json);
puts(sample1);
ok=json.contains("\"effectiveDate\"")||die();
Samplesample2=JsonFactory.fromJson(json,Sample.class);
puts("sample2",sample2);
puts("sample2",JsonFactory.toJson(sample2));
ok=sample1.equals(sample2);
}
The above generates the following JSON:
{
"url": "http://www.google.com",
"uri": "http://www.google.com",
"file": "/usr/local/bin/vertx",
"date": 1398455978940,
"persistId": "029f6ef3-3de6-40ec-bc94-a06b61ca9793",
"path": "/usr/local/bin/vertx",
"locale": "en_ca",
"timeZone": "PST",
"effectiveDate": 1398455978940
}