当前位置: 首页>>代码示例>>Java>>正文


Java IO.write方法代码示例

本文整理汇总了Java中io.advantageous.boon.core.IO.write方法的典型用法代码示例。如果您正苦于以下问题:Java IO.write方法的具体用法?Java IO.write怎么用?Java IO.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.advantageous.boon.core.IO的用法示例。


在下文中一共展示了IO.write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeValue

import io.advantageous.boon.core.IO; //导入方法依赖的package包/类
@Override
public void writeValue( File dest, Object value ) {
    IO.write( Paths.get(dest.toString()), serializerFactory.create().serialize(value).toString());
}
 
开发者ID:advantageous,项目名称:boon,代码行数:5,代码来源:ObjectMapperImpl.java

示例2: part9Options

import io.advantageous.boon.core.IO; //导入方法依赖的package包/类
public static void part9Options() throws Exception {

        puts ("\n\n\n", "\npart9Options");


        JsonParserFactory jsonParserFactory = new JsonParserFactory()
                .useFieldsFirst().useFieldsOnly().usePropertiesFirst().usePropertyOnly() //one of these
                .lax() //allow loose parsing of JSON like JSON Smart
                .strict() //opposite of lax
                .setCharset( StandardCharsets.UTF_8 ) //Set the standard charset, defaults to UTF_8
                .setChop( true ) //chops up buffer overlay buffer (more discussion of this later)
                .setLazyChop( true ) //similar to chop but only does it after map.get
                ;

        JsonSerializerFactory jsonSerializerFactory = new JsonSerializerFactory()
                .useFieldsFirst().useFieldsOnly().usePropertiesFirst().usePropertyOnly() //one of these
                //.addPropertySerializer(  )  customize property output
                //.addTypeSerializer(  )      customize type output
                .useJsonFormatForDates() //use json dates
                //.addFilter(  )   add a property filter to exclude properties
                .includeEmpty().includeNulls().includeDefaultValues() //override defaults
                .handleComplexBackReference() //uses identity map to track complex back reference and avoid them
                .setHandleSimpleBackReference( true ) //looks for simple back reference for parent
                .setCacheInstances( true ) //turns on caching for immutable objects
                ;



        final User diana = BeanUtils.copy( user );
        final User rick = BeanUtils.copy( user );
        diana.getName().setFirst( "Diana" );
        diana.setGender( User.Gender.FEMALE );
        rick.getName().setFirst( "Rick" );
        diana.setBirthDate( Dates.getUSDate( 8, 21, 1984 ) );
        List<User> users = Lists.list(  rick, diana );

        //You can use parser and serializer directly.
        final JsonParserAndMapper jsonParserAndMapper = jsonParserFactory.create();
        final JsonSerializer jsonSerializer = jsonSerializerFactory.create();

        File file = File.createTempFile( "userList", ".json" );
        String jsonString = jsonSerializer.serialize( users ).toString();

        puts( "JSON STRING", jsonString );

        IO.write( file.toString(), jsonString);
        List<User> users2 = jsonParserAndMapper.parseListFromFile( User.class, file.toString() );

        //Or you can pass them to the ObjectMapper interface you know and love, just pass the factories to it.
        ObjectMapper mapper = JsonFactory.create( jsonParserFactory, jsonSerializerFactory );


        mapper.writeValue( file, users  );
        List<User> userList = mapper.readValue( file, List.class, User.class  );
        puts (userList);
        puts ( mapper.writeValueAsString( userList ) );

        puts (userList);
        puts (users);
        boolean ok = userList.toString().equals ( users.toString() ) || die ( userList.toString() );



    }
 
开发者ID:advantageous,项目名称:boon,代码行数:65,代码来源:JsonTutorial.java

示例3: main

import io.advantageous.boon.core.IO; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {


        File file = File.createTempFile("foo", "json");

        final JsonParserAndMapper jsonMapper =
                new JsonParserFactory()
                        .createFastObjectMapperParser();

        final JsonSerializer jsonSerializer = new JsonSerializerFactory()
                .create();

        final Sales salesOut = new Sales(1, "foo");
        final String json = jsonSerializer.serialize(salesOut).toString();

        puts(json);


        IO.write(file.toPath(), json);

        final String jsonIn = IO.read(file);


        puts("OUT", salesOut, jsonIn);





        final Sales salesIn = jsonMapper.parse(Sales.class, jsonIn);

        puts("OUT", salesIn, salesOut);


        assertEquals(salesOut, salesIn);



    }
 
开发者ID:advantageous,项目名称:boon,代码行数:40,代码来源:JsonWorkingWithNonSerializableObjects.java

示例4: write

import io.advantageous.boon.core.IO; //导入方法依赖的package包/类
private void write(List<EndpointDefinition> fooServices) throws Exception {
    JsonSerializer jsonSerializer = new JsonSerializerFactory().create();
    String json = jsonSerializer.serialize(fooServices).toString();

    File outputFile = new File(dir, "fooBar.json");

    IO.write(outputFile.toPath(), json);

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:10,代码来源:ServiceDiscoveryWithFileSystemTest.java


注:本文中的io.advantageous.boon.core.IO.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。