Browse Source

json file -> inputstreamreader로 읽도록 처리

feature/auth
노승철 2 years ago
parent
commit
e638fd7da1
  1. 10
      src/main/java/com/palnet/biz/api/bas/flight/controller/BasFlightController.java

10
src/main/java/com/palnet/biz/api/bas/flight/controller/BasFlightController.java

@ -18,9 +18,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.FileReader; import java.io.*;
import java.io.IOException;
import java.io.Reader;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -37,11 +35,13 @@ public class BasFlightController {
public ResponseEntity<Object> getAirArea() throws IOException, ParseException { public ResponseEntity<Object> getAirArea() throws IOException, ParseException {
// 1. file read // 1. file read
Resource resource = new ClassPathResource("air/airgeo.json"); Resource resource = new ClassPathResource("air/airgeo.json");
Reader jsonFile = new FileReader(resource.getFile()); InputStream jsonInputStream = resource.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(jsonInputStream, "UTF-8");
BufferedReader reader = new BufferedReader(inputStreamReader);
// 2. json parsing // 2. json parsing
JSONParser jsonParser = new JSONParser(); JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(jsonFile); JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
// 3. body return // 3. body return
String type = (String) jsonObject.get("type"); String type = (String) jsonObject.get("type");

Loading…
Cancel
Save