How to import json file through Restful java api?

(Gourav Bhattacharya) #1

Please give me some syntax which helps me through it, If possible some links also.
my code:-1:

ObjectMapper mapper = new ObjectMapper();
String path = "C:\Users\Gourav Bhattacharya\Downloads\accounts\accounts.json";
byte[] jsonData = mapper.writeValueAsBytes(path);

	//BufferedReader br = new BufferedReader(new FileReader(path));
	JsonParser parser = new JsonFactory().createParser(jsonData);
	String jsonString = parser.getValueAsString();
	Map<String, Object> json = new HashMap<String, Object>();
	json.put("postDate",new Date());
	IndexResponse response = transportClient.prepareIndex("bank", "account", "1")
	        .setSource(json, XContentType.JSON)
	String _index = response.getIndex();
	String _type = response.getType();
	String _id = response.getId();
	long _version = response.getVersion();
	RestStatus status = response.status();
	System.out.println(_index + "\n" +_type+ "\n" + _id + "\n" +_version+ "\n" + status);

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.