mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-27 00:02:42 +00:00
#585 - Refactor of ScalarType jsonWrite() method such that it only takes JsonGenerator - part 3, remove JsonToken from jsonRead()
This commit is contained in:
@@ -43,9 +43,9 @@ public class JsonTester<T> {
|
||||
assertEquals(JsonToken.START_OBJECT, token);
|
||||
token = parser.nextToken();
|
||||
assertEquals(JsonToken.FIELD_NAME, token);
|
||||
token = parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
||||
T val1 = type.jsonRead(parser, token);
|
||||
T val1 = type.jsonRead(parser);
|
||||
assertEquals(value, val1);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.text.json.JsonContext;
|
||||
import com.avaje.tests.model.basic.TOne;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ScalarTypeBooleanTest {
|
||||
|
||||
JsonContext jsonContext = Ebean.getDefaultServer().json();
|
||||
|
||||
@Test
|
||||
public void json_true() {
|
||||
|
||||
TOne bean = new TOne();
|
||||
bean.setId(42);
|
||||
bean.setActive(true);
|
||||
|
||||
String json = jsonContext.toJson(bean);
|
||||
TOne tOne = jsonContext.toBean(TOne.class, json);
|
||||
|
||||
assertTrue(tOne.isActive());
|
||||
assertEquals(json, "{\"id\":42,\"active\":true}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_false() {
|
||||
|
||||
TOne bean = new TOne();
|
||||
bean.setId(42);
|
||||
bean.setActive(false);
|
||||
|
||||
String json = jsonContext.toJson(bean);
|
||||
TOne tOne = jsonContext.toBean(TOne.class, json);
|
||||
|
||||
assertFalse(tOne.isActive());
|
||||
assertEquals(json, "{\"id\":42,\"active\":false}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TJodaEntity;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.joda.time.LocalTime;
|
||||
@@ -43,4 +45,19 @@ public class ScalarTypeJodaLocalTimeTest {
|
||||
assertEquals(ts1, ts2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJson() {
|
||||
|
||||
LocalTime now = new LocalTime();
|
||||
|
||||
TJodaEntity bean = new TJodaEntity();
|
||||
bean.setId(42);
|
||||
bean.setLocalTime(now);
|
||||
|
||||
String json = Ebean.json().toJson(bean);
|
||||
TJodaEntity bean1 = Ebean.json().toBean(TJodaEntity.class, json);
|
||||
|
||||
assertEquals(bean1.getLocalTime(), now);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class ScalarTypePostgresHstoreTest {
|
||||
// simulate that here
|
||||
JsonToken token = parser.nextToken();
|
||||
assertEquals(JsonToken.START_OBJECT, token);
|
||||
return (Map<String,Object>)hstore.jsonRead(parser, token);
|
||||
return (Map<String,Object>)hstore.jsonRead(parser);
|
||||
}
|
||||
|
||||
private String generateJson(Map<String, Object> map) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user