added additional tests for the default deserialization of dates.
This commit is contained in:
parent
1cad54f7b1
commit
0b9c739a7b
|
@ -21,7 +21,6 @@ import java.lang.reflect.Array;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
|
|
@ -190,6 +190,11 @@ public class DefaultTypeAdaptersTest extends TestCase {
|
|||
assertEquals("\"" + DateFormat.getDateInstance().format(now) + "\"", json);
|
||||
}
|
||||
|
||||
public void testDefaultDateDeserialization() {
|
||||
Date date = new Date();
|
||||
assertEquals(date, gson.fromJson(gson.toJson(date), Date.class));
|
||||
}
|
||||
|
||||
public void testDefaultDateSerializationUsingBuilder() throws Exception {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
Date now = new Date();
|
||||
|
@ -197,6 +202,13 @@ public class DefaultTypeAdaptersTest extends TestCase {
|
|||
assertEquals("\"" + DateFormat.getDateInstance().format(now) + "\"", json);
|
||||
}
|
||||
|
||||
public void testDefaultDateDeserializationUsingBuilder() throws Exception {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
Date now = new Date();
|
||||
String json = gson.toJson(now);
|
||||
assertEquals(now, gson.fromJson(json, Date.class));
|
||||
}
|
||||
|
||||
public void testDateSerializationWithPattern() throws Exception {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
DateFormat formatter = new SimpleDateFormat(pattern);
|
||||
|
@ -205,7 +217,16 @@ public class DefaultTypeAdaptersTest extends TestCase {
|
|||
String json = gson.toJson(now);
|
||||
assertEquals("\"" + formatter.format(now) + "\"", json);
|
||||
}
|
||||
|
||||
|
||||
public void testDateDeserializationWithPattern() throws Exception {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
DateFormat formatter = new SimpleDateFormat(pattern);
|
||||
Gson gson = new GsonBuilder().setDateFormat(DateFormat.LONG).setDateFormat(pattern).create();
|
||||
Date now = new Date();
|
||||
String json = gson.toJson(now);
|
||||
assertEquals(now, gson.fromJson(json, Date.class));
|
||||
}
|
||||
|
||||
private static class ClassWithBigDecimal {
|
||||
BigDecimal value;
|
||||
ClassWithBigDecimal() { }
|
||||
|
|
Loading…
Reference in New Issue