本文整理汇总了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());
}
示例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() );
}
示例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);
}
示例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);
}