读取文件内容并转换为对象

1.private static String readFileAsStringWithAbsolutePath(final String path) {
		try {
			final InputStream is = new FileInputStream(new File(path));
			return IOUtils.toString(is);
		} catch (IOException e) {
			LOG.error("Unknow IOException: " + e.getMessage(), e);
			return null;
		}
	}
2.final ExpectedResult expectedResult = JsonParsingUtil.fromJson(message, ExpectedResult.class);

3.public class ExpectedResult {

	private List serviceIds;
	private List serviceOrders;
	private List ledgerDetails;
}
4.{
    "service_ids":[{
    	"id":93887621,
    	"event_type":"create",
    	"service_status":"A"
    }],
    "ledger_details":[
    ], 
    "service_orders":[
    ]
}

2中的message就是通过1中方法读取出来的,3是转换成的json对象,4是读取的文件内容即message

 
 

你可能感兴趣的:(读取文件内容并转换为对象)