mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
32 lines
761 B
Java
32 lines
761 B
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.json.transientproperties.EJsonTransientObject;
|
|
import org.junit.Test;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
public class TestJsonExcludeNull {
|
|
|
|
@Test
|
|
public void testToBeanToJson() throws Exception {
|
|
|
|
|
|
EJsonTransientObject bean = new EJsonTransientObject();
|
|
bean.setId(99L);
|
|
bean.setName(null);
|
|
|
|
JsonWriteOptions options = new JsonWriteOptions();
|
|
options.setInclude(JsonConfig.Include.NON_NULL);
|
|
|
|
String asJson = Ebean.json().toJson(bean, options);
|
|
|
|
String expectedJson = "{\"id\":99}";
|
|
|
|
assertEquals(expectedJson, asJson);
|
|
}
|
|
|
|
}
|