mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
package com.avaje.tests.json.include;
|
|
|
|
import com.avaje.ebean.Ebean;
|
|
import com.avaje.ebean.config.JsonConfig;
|
|
import com.avaje.ebean.text.json.JsonWriteOptions;
|
|
import com.avaje.tests.model.json.EBasicJsonMap;
|
|
import org.junit.Test;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
public class TestJsonExcludeEmptyMap {
|
|
|
|
@Test
|
|
public void testToBeanToJson_NonNull() throws Exception {
|
|
|
|
EBasicJsonMap bean = new EBasicJsonMap();
|
|
bean.setId(99L);
|
|
bean.setContent(new LinkedHashMap<>());
|
|
|
|
JsonWriteOptions options = new JsonWriteOptions();
|
|
options.setInclude(JsonConfig.Include.NON_NULL);
|
|
|
|
String asJson = Ebean.json().toJson(bean, options);
|
|
|
|
String expectedJson = "{\"id\":99,\"content\":{}}";
|
|
|
|
assertEquals(expectedJson, asJson);
|
|
}
|
|
|
|
@Test
|
|
public void testToBeanToJson_NonEmpty() throws Exception {
|
|
|
|
EBasicJsonMap bean = new EBasicJsonMap();
|
|
bean.setId(99L);
|
|
bean.setContent(new LinkedHashMap<>());
|
|
|
|
JsonWriteOptions options = new JsonWriteOptions();
|
|
options.setInclude(JsonConfig.Include.NON_EMPTY);
|
|
|
|
String asJson = Ebean.json().toJson(bean, options);
|
|
|
|
String expectedJson = "{\"id\":99,\"content\":{}}";
|
|
|
|
assertEquals(expectedJson, asJson);
|
|
}
|
|
}
|