mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
WIP on JSON refactor
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
|
||||
public class TestJsonBeanDescriptorParse extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
|
||||
BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
|
||||
|
||||
StringReader reader = new StringReader("{\"id\":123,\"name\":\"Hello rob\"}");
|
||||
JsonParser parser = Json.createParser(reader);
|
||||
|
||||
Customer customer = (Customer)descriptor.jsonRead(parser, null);
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(123), customer.getId());
|
||||
Assert.assertEquals("Hello rob", customer.getName());
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
Set<String> loadedProps = beanState.getLoadedProps();
|
||||
|
||||
Assert.assertEquals(2, loadedProps.size());
|
||||
Assert.assertTrue(loadedProps.contains("id"));
|
||||
Assert.assertTrue(loadedProps.contains("name"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,8 +44,8 @@ public class TestTextJsonSimple extends BaseTestCase {
|
||||
|
||||
});
|
||||
|
||||
// String s = json.toJsonString(list, true);
|
||||
String s = json.toJsonString(list, true, options);
|
||||
String s = json.toJsonString(list, true);
|
||||
// String s = json.toJsonString(list, true, options);
|
||||
|
||||
System.out.println(s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user