I added support for timezone, locale, UUID, URL, URI, File and Path.
/**
*
* @author l man
*/
public static class Sample
implements Serializable {
private static final long serialVersionUID = 1L;
private URL url;
private URI uri;
private File file;
private Date date;
private final UUID persistId;
private Path path;
private Locale locale;
private TimeZone timeZone;
private static final AtomicLongFieldUpdater<Sample> EFFECTIVEDATE_UPDATER
= AtomicLongFieldUpdater.newUpdater(Sample.class, "effectiveDate");
public Sample() {
this.persistId = UUID.randomUUID();
this.effectiveDate = System.currentTimeMillis();
try {
url = new URL("http://www.google.com");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
uri = new URI("http://www.google.com");
} catch (URISyntaxException e) {
e.printStackTrace();
}
file =new File("/usr/local/bin/vertx");
date = new Date();
path = file.toPath();
locale = Locale.CANADA;
timeZone = TimeZone.getTimeZone("PST");
}
public UUID getPersistId() {
return persistId;
}
private volatile long effectiveDate;
public final long getEffectiveDate() {
return effectiveDate;
}
public final void setEffectiveDate(long effectiveDate) {
EFFECTIVEDATE_UPDATER.compareAndSet(this, this.effectiveDate, effectiveDate);
}
...
@Test
public void test4() {
Sample sample1 = new Sample();
String json = JsonFactory.toJson(sample1);
puts(json);
puts (sample1);
ok = json.contains("\"effectiveDate\"") || die();
Sample sample2 = 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
}
RichardHightower referenced this issue from a commit 2 minutes ago
5075035 |
RichardHightower closed this just now