/** * @author javamonkey79 * https://github.com/boonproject/boon/issues/355 */ @Test public void includeEmptyString() { Cat mittens = new Cat("mittens", "calico", ""); Assert.assertEquals("{\"name\":\"mittens\",\"type\":\"calico\",\"sex\":\"\"}", String.valueOf(new JsonSerializerFactory().setIncludeEmpty(true).create().serialize(mittens))); }
@Test public void testBug() { Employee rick = new Employee(); JsonSerializer serializer = new JsonSerializerFactory() .setIncludeEmpty( true ).setUseAnnotations( false ) .setCacheInstances( false ) .setIncludeNulls( true ) .create(); String sRick = serializer.serialize( rick ).toString(); //uts( sRick ); AllTypes foo = new AllTypes(); foo.ignoreMe = "THIS WILL NOT PASS"; foo.ignoreMe2 = "THIS WILL NOT PASS EITHER"; foo.ignoreMe3 = "THIS WILL NOT PASS TOO"; foo.setDate( new Date() ); foo.setBar( FooEnum.BAR ); foo.setFoo( FooEnum.FOO ); foo.setString( "Hi Mom" ); AllTypes foo2 = BeanUtils.copy( foo ); foo.setAllType( foo2 ); foo2.setString( "Hi Dad" ); foo.setAllTypeList( Lists.list( BeanUtils.copy( foo2 ), BeanUtils.copy( foo2 ) ) ); String sFoo = serializer.serialize( foo ).toString(); //uts( sFoo ); }
@Test public void bug2() { Employee rick = new Employee(); JsonSerializer serializer = new JsonSerializerFactory() .setIncludeEmpty( true ).setUseAnnotations( false ) .setCacheInstances( false ) .create(); String sRick = serializer.serialize( rick ).toString(); outputs( sRick ); AllTypes foo = new AllTypes(); foo.ignoreMe = "THIS WILL NOT PASS"; foo.ignoreMe2 = "THIS WILL NOT PASS EITHER"; foo.ignoreMe3 = "THIS WILL NOT PASS TOO"; foo.setDate( new Date() ); foo.setBar( FooEnum.BAR ); foo.setFoo( FooEnum.FOO ); foo.setString( "Hi Mom" ); AllTypes foo2 = BeanUtils.copy( foo ); foo.setAllType( foo2 ); foo2.setString( "Hi Dad" ); foo.setAllTypeList( Lists.list( BeanUtils.copy( foo2 ), BeanUtils.copy( foo2 ) ) ); String sFoo = serializer.serialize( foo ).toString(); outputs( sFoo ); }