#1882 - ENH: Add JsonContext.toJsonPretty() ... for pretty JSON output of beans and lists of beans

This commit is contained in:
rob bygrave
2019-12-04 22:55:52 +13:00
parent 89c05007c2
commit 937df1395c
5 changed files with 51 additions and 14 deletions
@@ -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\": [ {");
}
}