From 4bcd0889101f4434d163dea5aeb98c45977f8ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Fri, 7 Jun 2024 15:26:58 +0900 Subject: [PATCH] =?UTF-8?q?refactor:fcm=20Gson()=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/firebase/FirebaseConfig.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java index cc32c8a..6f731eb 100644 --- a/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java +++ b/src/main/java/com/hanaro/triptogether/common/firebase/FirebaseConfig.java @@ -4,6 +4,7 @@ import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.firebase.messaging.FirebaseMessaging; +import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.stream.JsonReader; @@ -22,22 +23,22 @@ public FirebaseApp firebaseApp() throws IOException { InputStream resource = new ClassPathResource("triptogether-e7bac-firebase-adminsdk-peiki-127517aa66.json").getInputStream(); - JsonReader jsonReader = new JsonReader(new InputStreamReader(resource)); - jsonReader.setLenient(true); +// JsonReader jsonReader = new JsonReader(new InputStreamReader(resource)); +// jsonReader.setLenient(true); - // JsonParser를 사용하여 JSON 데이터를 파싱 -// var jsonElement = JsonParser.parseReader(jsonReader); -// String jsonString = jsonElement.toString(); + byte[] jsonBytes = resource.readAllBytes(); + String jsonString = new String(jsonBytes, StandardCharsets.UTF_8); - // JsonParser를 사용하여 JSON 데이터를 파싱 - JsonObject jsonObject = JsonParser.parseReader(jsonReader).getAsJsonObject(); + // Gson을 사용하여 JSON 문자열을 JsonObject로 파싱 + Gson gson = new Gson(); + JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject(); - // JSON 데이터를 문자열로 변환 - String jsonString = jsonObject.toString(); + // JsonObject를 다시 문자열로 변환 + String jsonFormattedString = gson.toJson(jsonObject); + // 문자열을 다시 InputStream으로 변환 + InputStream jsonInputStream = new ByteArrayInputStream(jsonFormattedString.getBytes(StandardCharsets.UTF_8)); - // 파싱된 JSON 데이터를 다시 InputStream으로 변환 - InputStream jsonInputStream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)); FirebaseOptions options = FirebaseOptions .builder()