google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.16k stars 4.27k forks source link

Javascript #2622

Closed khaouitiabdelhakim closed 5 months ago

khaouitiabdelhakim commented 5 months ago

Problem solved by the feature

Feature description

Why GSON is not available in the web world like in javascript?

Alternatives / workarounds

Marcono1234 commented 5 months ago

Why GSON is not available in the web world like in javascript?

Can you please clarify what you mean by that? Gson is a Java library; Java and JavaScript are completely different languages. Do you want to use a library similar to Gson in JavaScript running in the browser?

JeremiahRanen7 commented 5 months ago

Could you kindly clarify your request further? Providing additional details would enable me to assist you more effectively.

khaouitiabdelhakim commented 5 months ago

Hi, I would like to ask you if such a library exists in javascript. Because I have an android app that uses this library and I am expanding it to the web. Is there any alternative.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremiah Ranen R @.> Sent: Sunday, February 18, 2024 8:38:49 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

Could you kindly clarify your request further? Providing additional details would enable me to assist you more effectively.

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1951425158, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXQBU7XAA4KIEDNQZPDYUJKETAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJRGQZDKMJVHA. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

As of my knowledge , there is no library called gson in JavaScript but in java , there is a library called gson .

In Java : It is used like , for parsing json strings to json objects and stringifies json objects to json strings. It does serialization and deserialization of the json objects. Mostly used for transferring data between server and clients in the form of network requests.

Now , if you want to expand the android app to the web , you can use built in json methods of JavaScript like the below:

image

You can refer to the below link on how to use the stringify and parse methods. It would really be helpful. https://www.digitalocean.com/community/tutorials/js-json-parse-stringify

But if you want to work with dedicated json libraries , I would recommend you to use FastJson , lodash , underscore.js , etc.; There are a lots of libraries in JavaScript that work with JSON.

I hope this helps you. If you still have doubts , you can ask me about it.

JeremiahRanen7 commented 5 months ago

I also wanted to tell you that gson was developed by google. 👍 Hope you find out your requirement.

khaouitiabdelhakim commented 5 months ago

I want really to thank you so much for such a huge amount of information my friend.

Yes, that's why I have asked. I have a great android app like Spotify it is called Faborfy which means the free Spotify (you can find it on Google play) and I used to use gson, so all the data are stored in Firebase using the stringfy of gson. So when I tried to use json parsing in the web (react+ vite) I found like the normal json is not understanding the string that I get from firebase.

And that is the reason why I asked if there is any gson like for the web.

Best, KHAOUITI.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 5:37:59 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

As of my knowledge , there is no library called gson in JavaScript but in java , there is a library called gson .

In Java : It is used like , for parsing json strings to json objects and stringifies json objects to json strings. It does serialization and deserialization of the json objects. Mostly used for transferring data between server and clients in the form of network requests.

Now , if you want to expand the android app to the web , you can use built in json methods of JavaScript like the below:

image.png (view on web)https://github.com/google/gson/assets/141173239/c776d9c2-5d28-400b-af0b-e18ba2462a85

You can refer to the below link on how to use the stringify and parse methods. It would really be helpful. https://www.digitalocean.com/community/tutorials/js-json-parse-stringify

But if you want to work with dedicated json libraries , I would recommend you to use FastJson , lodash , underscore.js , etc.; There are a lots of libraries in JavaScript that work with JSON.

I hope this helps you. If you still have doubts , you can ask me about it.

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952848692, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXXB4VLCKBJ5EDLXOFDYUN5WPAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHA2DQNRZGI. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

That's great to here from you my friend. Really happy to see that you have found something helpful 👍 Best wishes to complete the web app soon 💯 Jeremiah Ranen R.

khaouitiabdelhakim commented 5 months ago

I want also to tell you that gson in Kotlin undertands the new line breaker \n inside a string, in my case I have so much \n s in lyrics key , but this in json (web) throws an error. It is unable to oarse that characters and a lot of disimilaties.

I hope you get my point.

And thanks in advance for all.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: KHAOUITI ABDELHAKIM @.> Sent: Monday, February 19, 2024 5:44:07 PM To: google/gson @.>; google/gson @.> Cc: Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

I want really to thank you so much for such a huge amount of information my friend.

Yes, that's why I have asked. I have a great android app like Spotify it is called Faborfy which means the free Spotify (you can find it on Google play) and I used to use gson, so all the data are stored in Firebase using the stringfy of gson. So when I tried to use json parsing in the web (react+ vite) I found like the normal json is not understanding the string that I get from firebase.

And that is the reason why I asked if there is any gson like for the web.

Best, KHAOUITI.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 5:37:59 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

As of my knowledge , there is no library called gson in JavaScript but in java , there is a library called gson .

In Java : It is used like , for parsing json strings to json objects and stringifies json objects to json strings. It does serialization and deserialization of the json objects. Mostly used for transferring data between server and clients in the form of network requests.

Now , if you want to expand the android app to the web , you can use built in json methods of JavaScript like the below:

image.png (view on web)https://github.com/google/gson/assets/141173239/c776d9c2-5d28-400b-af0b-e18ba2462a85

You can refer to the below link on how to use the stringify and parse methods. It would really be helpful. https://www.digitalocean.com/community/tutorials/js-json-parse-stringify

But if you want to work with dedicated json libraries , I would recommend you to use FastJson , lodash , underscore.js , etc.; There are a lots of libraries in JavaScript that work with JSON.

I hope this helps you. If you still have doubts , you can ask me about it.

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952848692, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXXB4VLCKBJ5EDLXOFDYUN5WPAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHA2DQNRZGI. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

Ok , I understand your need! But may I know where this json data comes from ? Is it from an external source like an API or a file in your local storage? This would be helpful.

Also it would be helpful if you could give me a sample json data that you use!!

khaouitiabdelhakim commented 5 months ago

This is my app

https://play.gohttps://play.google.com/store/apps/details?id=com.abdelhakim.faborfyogle.com/store/apps/details?id=com.abdelhakim.faborfhttps://play.google.com/store/apps/details?id=com.abdelhakim.faborfyy

It is like chrome but with the design of Spotify-like.

I have a class data class Music (title, artist, lyrics.....) and I have for example the favorite songs which is an ArrayList of Music objects. So with gson in my kotlin android app I use it to save the favorite to the realtime database of firebase as a string and do it the inverse way to retrieve my arraylist of Music.

Example

[{"artUrl":"https://cdns-images.dzcdn.net/images/cover/d78f12a2402dfbb1026e0c709f02b401/500x500.jpg","isSongRight":false,"lyric":"Her şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\n","playCount":4,"source":"dl.musicdel.ir","title":"Herkes Gibisin Semicenk","url":"https://dl.musicdel.ir/Music/1401/03/semicenk_herkes_gibisin%20128.mp3"},{"artUrl":"https://i1.sndcdn.com/artworks-1URmYrFXyqSO9Mcd-mqvweg-t500x500.jpg","isSongRight":false,"lyric":"Daha çok değil üstünden, seneler geçmedi ki \nYorgunum, \"Artık bu son!\" deyip geçebildik mi? \n\nDerin bir iz bıraktı içimde taze yaran \nBir gün elbet kapanır \nKapandı yarım kalan sayfamız mümkün değil \nBu son değil \n\nAyrılığın acısı \nSorulur mu yanana? \nAşka düştüm düşeli \nKül oldu bahtım kara \n\nAyrılığın acısı \nSorulur mu yanana? \nAşka düştüm düşeli \nKül oldu bahtım kara \n\nDerin bir iz bıraktı içimde taze yaran \nBir gün elbet kapanır \nKapandı yarım kalan sayfamız mümkün değil \nBu son değil \n\nAyrılığın acısı \nSorulur mu yanana? \nAşka düştüm düşeli \nKül oldu bahtım kara \n\nAyrılığın acısı \nSorulur mu yanana? \nAşka düştüm düşeli \nKül oldu bahtım kara \n\nAyrılığın acısı \nSorulur mu yanana? \nAşka düştüm düşeli \n\n","playCount":4,"source":"mp3indirdur.life","title":"Kül Merve Özbey","url":"https://mp3indirdur.life/Merve-Ozbey-Ayriligin-Acisi-115577?dinle\u003d1"},{"artUrl":"https://m.media-amazon.com/images/I/41MXxIR-aCL._UXNaN_FMjpg_QL85_.jpg","isSongRight":false,"lyric":"Gidene dur demem başkası olsa \nBir yanım buz gibiydi ateş oldun \nUnutma her şeyi yoluna koy\u0027cam \nOlmadın inatla, dinle iki dak\u0027ka \n\nHer şey üst üste geldi çok yoruldum \nDuydum onunla ner\u0027de ne konuştun \nUğruna derdim oldu yüküm arttı \nKavgaya karıştım söyle bu gurur mu? \n\nBile bile bana yine zehir ediyo\u0027n \nNe sandın beni be, kendime yetiyo\u0027m \nDünya kadar derdim çok ama yine deniyo\u0027m \nBi nedenimiz yok inan sevenimiz yok, gülüm \n\nBile bile bana yine zehir ediyo\u0027n \nNe sandın beni be, kendime yetiyo\u0027m \nDünya kadar derdim çok ama yine deniyo\u0027m \nBi nedenimiz yok inan sevenimiz yok, gülüm \n\nBi yanım olsan, gönlümde yerin olsan \nN\u0027aparım sensiz yoksan bir an düşünemiyo\u0027m \nGeceleri biten şişelerin hiç hesabı yok \nBi neden mi arıyo\u0027n bitirmek için \nAma benim zararım var \nUnutmak için gün sayıyo\u0027m \nBi neden söyle bana de sevmedim hiçbir zaman \nOlmazdı dostumu satmazdım \nKader \nYüzüme bakmazdı zaten ilk değilsin giden \n\nHer şeyden geçtim cano \nBi\u0027 de senden geçsem tamam \nİnadım var düşmem daha \nAğlatmam kansızlara \nSeni asla bilmeyeceksin \nBelki de beni görmeyeceksin \nBenden önce ölmeyeceksin \nAma şunu bil \nBenim kadar sevmeyeceksin \n\nBile bile bana yine zehir ediyo\u0027n \nNe sandın beni be, kendime yetiyo\u0027m \nDünya kadar derdim çok ama yine deniyo\u0027m \nBi nedenimiz yok inan sevenimiz yok, gülüm \n\nBile bile bana yine zehir ediyo\u0027n \nNe sandın beni be, kendime yetiyo\u0027m \nDünya kadar derdim çok ama yine deniyo\u0027m \nBi nedenimiz yok inan sevenimiz yok, gülüm \n\nAlo, alo \n\n","playCount":11,"source":"grand.az","title":"Ayaz Erdoğan - Gülüm","url":"https://grand.az/uploads/files/2023-08/1691264641_ayaz-erdogan-gulum-2023.mp3"},{"artUrl":"https://cdns-images.dzcdn.net/images/cover/6769498eadcb208af8201d101453c942/500x500.jpg","isSongRight":false,"lyric":"Bana el salla baharlarımı çaldığın bu hayattan \nBurda geçilmiyor ne kar ne kış ne ayazdan \nHiçbir farkı kalmamış umudumun bir bataktan \nArtık güneş yerine ay doğar bu şafaktan \n\nBana kalbinde kurduğun barikattan \nKalan sadece yıkık enkazlar \nGeleceği göremedim seninle \nGeçmişe biriken toz topraktan \n\nDayanır kapıma kapıma gece gece vurur aşk \nSabaha kadar eder yine gönlümü darp \nHem yanına hem yarına kâr kalır ah \nBana düşen de biten hasrete yas \n\nDayanır kapıma kapıma gece gece vurur aşk \nSabaha kadar eder yine gönlümü darp \nHem yanına hem yarına kâr kalır ah \nBana düşen de biten hasrete yas \n\nBana kalbinde kurduğun barikattan \nKalan sadece yıkık enkazlar \nGeleceği göremedim seninle \nGeçmişe biriken toz topraktan \n\nDayanır kapıma kapıma gece gece vurur aşk \nSabaha kadar eder yine gönlümü darp \nHem yanına hem yarına kâr kalır ah \nBana düşen de biten hasrete yas \n\nDayanır kapıma kapıma gece gece vurur aşk \nSabaha kadar eder yine gönlümü darp \nHem yanına hem yarına kâr kalır ah \nBana düşen de biten hasrete yas \n\n","playCount":34,"source":"mp3indirdur.life","title":"Irmak Arici Yas","url":"https://mp3indirdur.life/Irmak-Arici-Yas-feat-Doganay-Karadeniz-212956?dinle\u003d1"},{"artUrl":"https://artwork.anghcdn.co/webp/?id\u003d79006105\u0026size\u003d320","isSongRight":false,"lyric":"اللي يبي يزعل خله يزعل تعبت اسامح اسال\nقلبي كافي تحمل هموم هموم\nمحد فيني ابد حاس شايل هم الناس\nمن اليوم ولله خلاص هموم هموم\nو بعد بعد بعد مالي مالي شغل باحد\nو ابد ابد بعد ما اهتم ولا احس باحد\nمو كافي اذيه فيكم ماعليه\nحملتوني اسيه بعيش لنفسي اليوم\nاحرق بدمي و اراضي و اساعد على الفاضي\nترضاها ياقاضي اعيش انا مظلوم\nلمى تروح المصالح الحلو يصير مالح\nمن اليوم و رايح خلاص ماني ملزوم\nلا بطيبهم ولا بشرهم انا قلبي اكتفه\nماعاد ابي شي منهم مابي هالمعرفه\nاللي يبي يزعل خله يزعل تعبت اسامح اسال\nقلبي كافي تحمل هموم هموم\nمحد فيني ابد حاس شايل هم الناس\nمن اليوم ولله خلاص هموم هموم\nو بعد بعد بعد مالي مالي شغل باحد\nو ابد ابد بعد ما اهتم ولا احس باحد\nمو كافي اذيه فيكم ماعليه\nحملتوني اسيه بعيش لنفسي اليوم\nاحرق بدمي و اراضي و اساعد على الفاضي\nترضاها ياقاضي اعيش انا مظلوم\nلمى تروح المصالح الحلو يصير مالح\nمن اليوم و رايح خلاص ماني ملزوم\nلا بطيبهم ولا بشرهم انا قلبي اكتفه\nماعاد ابي شي منهم مابي هالمعرفه\n","playCount":26,"source":"cdn1.esm3.com","title":"اللي يبي يزعل سيف الفيصل","url":"https://cdn1.esm3.com/music/4558/m280244.mp3"}]

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 6:07:12 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

Ok , I understand your need! But may I know where this json data comes from ? Is it from an external source like an API or a file in your local storage? This would be helpful.

Also it would be helpful if you could give me a sample json data that you use!!

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952895256, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXSVXN2ARSFN2RYUKY3YUOBEBAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHA4TKMRVGY. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

Ok , when you try to use this data in the web , first check whether you have formatted your json correctly because each "\n" within a string should be formatted well like "\n". It should be properly escaped.

Ok try this out and tell me! I am just telling you to correct your json data if you have formatted it wrong use json validators in the internet for free

khaouitiabdelhakim commented 5 months ago

I did not get you! Could you please explain further more? Because it is that way that gson has formatted the arraylist it is great working with me on mobile.

I do not know if gson format the arraylist to another version of json or just the standard one?

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 6:44:31 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

Ok , when you try to use this data in the web , first check whether you have formatted your json correctly because each "\n" within a string should be formatted well like "\n". It should be properly escaped.

Ok try this out and tell me! I am just telling you to correct your json data if you have formatted it wrong use json validators in the internet for free

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952943256, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXWWKBFTNZQEWSA7DGTYUOFP3AVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHE2DGMRVGY. You are receiving this because you authored the thread.Message ID: @.***>

khaouitiabdelhakim commented 5 months ago

I did not see the difference between the 2 \n in your answer each "\n" within a string should be formatted well like "\n".

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 6:44:31 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

Ok , when you try to use this data in the web , first check whether you have formatted your json correctly because each "\n" within a string should be formatted well like "\n". It should be properly escaped.

Ok try this out and tell me! I am just telling you to correct your json data if you have formatted it wrong use json validators in the internet for free

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952943256, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXWWKBFTNZQEWSA7DGTYUOFP3AVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHE2DGMRVGY. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

ok , to use it in the web , it is much different compared to kotlin. I need some answers from you ? Is the JSON data coming from an api , if yes , ok - that's great if it is coming from an api , it would definitely come in a json string object (I am talking about JavaScript) you then need to parse it . Also if you are sending some json data to your database for storage , you cannot send it to the database or server in the form of a json object , you need to send it in the form of a json string

Like , for example :

const jsonData = [{"artUrl":"https://cdns-images.dzcdn.net/images/cover/d78f12a2402dfbb1026e0c709f02b401/500x500.jpg","isSongRight":false,"lyric":"Her şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\n","playCount":4,"source":"dl.musicdel.ir","title":"Herkes Gibisin Semicenk","url":"https://dl.musicdel.ir/Music/1401/03/semicenk_herkes_gibisin%20128.mp3"}];

const favoriteSongs = JSON.parse(jsonData);

Then , convert array of Music objects back to JSON string before storing in Firebase const jsonToSave = JSON.stringify(favoriteSongs); Now you can save jsonToSave to Firebase Realtime Database

Can you see the structure of the json string : [{ data }] I hope this helps you , or still if you have any doubt ,explain me in more detail about what your problem is , how is it in your mobile app and how do you want it in your website using JavaScript?

khaouitiabdelhakim commented 5 months ago

I do not get data from an api, I’m suing gson only to store the data of the user toward and back from firebase using gson and I want to do the same for the web so the json must understand the string saved in firebase as it is, else I should have 2 entries in the realtime database one for mobile and another for pc, but this is not what I want. I want the same string should be great for gson (Kotlin) and also works for json (web)

From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 7:17 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

ok , to use it in the web , it is much different compared to kotlin. I need some answers from you ? Is the JSON data coming from an api , if yes , ok - that's great if it is coming from an api , it would definitely come in a json string object (I am talking about JavaScript) you then need to parse it . Also if you are sending some json data to your database for storage , you cannot send it to the database or server in the form of a json object , you need to send it in the form of a json string

Like , for example :

const jsonData = [{"artUrl":"https://cdns-images.dzcdn.net/images/cover/d78f12a2402dfbb1026e0c709f02b401/500x500.jpg","isSongRight":false,"lyric":"Her şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\n","playCount":4,"source":"dl.musicdel.ir","title":"Herkes Gibisin Semicenk","url":"https://dl.musicdel.ir/Music/1401/03/semicenk_herkes_gibisin%20128.mp3"}];

const favoriteSongs = JSON.parse(jsonData);

Then , convert array of Music objects back to JSON string before storing in Firebase const jsonToSave = JSON.stringify(favoriteSongs); Now you can save jsonToSave to Firebase Realtime Database

Can you see the structure of the json string : [{ data }] I hope this helps you , or still if you have any doubt ,explain me in more detail about what your problem is , how is it in your mobile app and how do you want it in your website using JavaScript?

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952981531, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXR3KNHTPWSNTA35SBDYUOJLFAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHE4DCNJTGE. You are receiving this because you authored the thread.Message ID: @.***>

khaouitiabdelhakim commented 5 months ago

When the user sign in I got all their saved data

currentUserRef.addListenerForSingleValueEvent(object : ValueEventListener { override fun onDataChange(dataSnapshot: DataSnapshot) { val userData = dataSnapshot.value as? Map<, >

    // Retrieve favorites
    val favouriteSongsJson = userData?.get("favorites") as? String
    if (favouriteSongsJson != null) {
        FavouriteActivity.favouriteSongs =
            GsonBuilder().create().fromJson(favouriteSongsJson, MainActivity.typeToken1)
    }
    editor.putString("favouriteSongs", GsonBuilder().create().toJson(FavouriteActivity.favouriteSongs))

and when the user want to save it I save it as

private fun saveChangesToFirebase(){ val user = mAuth.currentUser if (isThereInternet(this) && user!=null) { val currentUser = database.child("users").child(user.uid) val playedSongString = GsonBuilder().create().toJson(JustPlayActivity.ListOfSongs) val favoriteSongString = GsonBuilder().create().toJson(FavouriteActivity.favouriteSongs) val playlistsString = GsonBuilder().create().toJson(PlaylistsActivity.musicPlaylistList) val searchString = GsonBuilder().create().toJson(JustPlayActivity.searchHistory)

    val userData = User(
        id = user.uid,
        played = playedSongString,
        favorites = favoriteSongString,
        playlists = playlistsString,
        search =  searchString
    )

    currentUser.setValue(userData)

    Log.i("savingChangesToFirebase", "savingChangesToFirebase")
}

}

From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 7:17 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

ok , to use it in the web , it is much different compared to kotlin. I need some answers from you ? Is the JSON data coming from an api , if yes , ok - that's great if it is coming from an api , it would definitely come in a json string object (I am talking about JavaScript) you then need to parse it . Also if you are sending some json data to your database for storage , you cannot send it to the database or server in the form of a json object , you need to send it in the form of a json string

Like , for example :

const jsonData = [{"artUrl":"https://cdns-images.dzcdn.net/images/cover/d78f12a2402dfbb1026e0c709f02b401/500x500.jpg","isSongRight":false,"lyric":"Her şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nNe ara bu duruma düştük? Saftı gönlüm çabuk kaçtı elimden \nBoşa geçti gördüm ömrümden çaldığın o günler \nKırıkları vardır elbet yaşamın bir parçasıydı herşey \nUmut edip anılanlar, yakılanlar, yıkılanlar \nFaydası yok sözlerin her nefeste başa sarar Özlem\u0027in \nBeni yoran bu kasveti tutamadım Erken çözüldü dizlerim \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\nHer şey bitermiş zamanla \nİçinde kalmasın söyle bilelim \nBana layık soğuk vedansa \nUnuttum artık herkes gibisin \n\n","playCount":4,"source":"dl.musicdel.ir","title":"Herkes Gibisin Semicenk","url":"https://dl.musicdel.ir/Music/1401/03/semicenk_herkes_gibisin%20128.mp3"}];

const favoriteSongs = JSON.parse(jsonData);

Then , convert array of Music objects back to JSON string before storing in Firebase const jsonToSave = JSON.stringify(favoriteSongs); Now you can save jsonToSave to Firebase Realtime Database

Can you see the structure of the json string : [{ data }] I hope this helps you , or still if you have any doubt ,explain me in more detail about what your problem is , how is it in your mobile app and how do you want it in your website using JavaScript?

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1952981531, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXR3KNHTPWSNTA35SBDYUOJLFAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJSHE4DCNJTGE. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

So you need a consistent JSON Structure and you also want to maintain compatibility between the JSON format used in your Kotlin Android app with Gson and the JSON format used in your web application? Right , well then give me some time , I will come up with an idea Because we need to come up with a tool that should be compatible with the JSON Structure that you use in the kotlin app we also need a tool or any plugin / feature / anything which ensures that the data saved in Firebase from the Android app can be correctly read and interpreted by your web application, and vice versa. Give me some time . buddy!! 👍

khaouitiabdelhakim commented 5 months ago

You have all the time, I want to deeply thank you for your time. I really appreciate it

best regards, buddy

From: Jeremiah Ranen R @.> Sent: Monday, February 19, 2024 7:37 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

So you need a consistent JSON Structure and you also want to maintain compatibility between the JSON format used in your Kotlin Android app with Gson and the JSON format used in your web application? Right , well then give me some time , I will come up with an idea Because we need to come up with a tool that should be compatible with the JSON Structure that you use in the kotlin app we also need a tool or any plugin / feature / anything which ensures that the data saved in Firebase from the Android app can be correctly read and interpreted by your web application, and vice versa. Give me some time . buddy!! 👍

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1953003755, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXRZU2XVLCHCUBBZIJDYUOLVXAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJTGAYDGNZVGU. You are receiving this because you authored the thread.Message ID: @.***>

eamonnmcmanus commented 5 months ago

I'm going to close this since it doesn't seem to be an issue with Gson as such. Feel free to continue the discussion here, though. I've also just enabled Discussions here, which might be a more appropriate place for future discussions.

khaouitiabdelhakim commented 5 months ago

Thanks Eamonn.


From: Éamonn McManus @.> Sent: Tuesday, February 20, 2024 5:29 PM To: google/gson @.> Cc: KHAOUITI ABDELHAKIM @.>; Author @.> Subject: Re: [google/gson] Javascript (Issue #2622)

Closed #2622https://github.com/google/gson/issues/2622 as not planned.

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#event-11864387985, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXUIALLGIGLBEIVOOY3YUTFPPAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRHA3DIMZYG44TQNI. You are receiving this because you authored the thread.Message ID: @.***>

JeremiahRanen7 commented 5 months ago

Hi hakim , did you come up with a solution ? Did you solve the problem you were facing?

khaouitiabdelhakim commented 5 months ago

No yet friend

On Feb 22, 2024 16:43, Jeremiah Ranen R @.***> wrote:

Hi hakim , did you come up with a solution ? Did you solve a problem?

— Reply to this email directly, view it on GitHubhttps://github.com/google/gson/issues/2622#issuecomment-1959720968, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3QVHXWDCPYUMMUMXPYSXLDYU5RTNAVCNFSM6AAAAABDMVSRI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJZG4ZDAOJWHA. You are receiving this because you authored the thread.Message ID: @.***>