Skip to content

Commit

Permalink
Merge pull request #148 from Hanaro-trip-together-bank/feature/dues_paid
Browse files Browse the repository at this point in the history
refactor:fcm Gson()사용
  • Loading branch information
ny2060 authored Jun 7, 2024
2 parents 7c74cd0 + 4bcd088 commit 774b306
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 774b306

Please sign in to comment.