mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1882 - ENH: Add JsonContext.toJsonPretty() ... for pretty JSON output of beans and lists of beans
This commit is contained in:
@@ -17,7 +17,7 @@ public class JsonBeanReaderTest extends BaseTestCase {
|
||||
static JsonContext json = Ebean.json();
|
||||
|
||||
@Test
|
||||
public void read() throws Exception {
|
||||
public void read() {
|
||||
|
||||
JsonParser parser = getParser();
|
||||
JsonBeanReader<Customer> beanReader = json.createBeanReader(Customer.class, parser, null);
|
||||
@@ -40,7 +40,7 @@ public class JsonBeanReaderTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forJson() throws Exception {
|
||||
public void forJson() {
|
||||
|
||||
JsonParser parser = getParser();
|
||||
JsonBeanReader<Customer> beanReader = json.createBeanReader(Customer.class, parser, null);
|
||||
|
||||
@@ -81,6 +81,20 @@ public class JsonContextTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toJsonPretty() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> orders = DB.find(Order.class)
|
||||
.select("status")
|
||||
.fetch("customer", "id, name")
|
||||
.findList();
|
||||
|
||||
String json = DB.json().toJsonPretty(orders);
|
||||
assertThat(json).contains("[ {");
|
||||
assertThat(json).contains("\"customer\": {");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toObject() {
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.ebeaninternal.server.text.json;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.FetchPath;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.text.PathProperties;
|
||||
@@ -8,7 +8,6 @@ import org.junit.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -16,22 +15,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class WriteJsonTest {
|
||||
|
||||
@Test
|
||||
public void test_push() throws IOException {
|
||||
public void test_push() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
FetchPath fetchPath = PathProperties.parse("id,status,name,customer(id,name,billingAddress(street,city)),details(qty,product(sku,prodName))");
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class);
|
||||
Query<Order> query = DB.find(Order.class);
|
||||
|
||||
fetchPath.apply(query);
|
||||
List<Order> list = query.findList();
|
||||
|
||||
String json = Ebean.json().toJson(list);
|
||||
System.out.println(json);
|
||||
String json = DB.json().toJsonPretty(list);
|
||||
|
||||
assertThat(json).contains("\"customer\":{");
|
||||
assertThat(json).contains("\"billingAddress\":{");
|
||||
assertThat(json).contains("\"details\":[{");
|
||||
assertThat(json).contains("\"customer\": {");
|
||||
assertThat(json).contains("\"billingAddress\": {");
|
||||
assertThat(json).contains("\"details\": [ {");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user