Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON serialization for settings #9887

Closed
wants to merge 3 commits into from

Conversation

litetex
Copy link
Member

@litetex litetex commented Mar 5, 2023

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

Replaces Java serialization with JSON serialization

This was changed inside

  • Importing/Exporting of settings
  • Unfinished Downloads (Downloadmission)1
  • StateSaver1

1 Ignored for now because they only store the data internally, which makes them irrelevant and the effort is too great; might be fixed later in another PR (StateSaver may e.g. be replaced by Icepick)

Additionally a bug was fixed where the export of the database was not possible because it was not initialized.

⚠️ Note that after merging this PR importing of existing settings won't work, due to the new format!
It's highly recommended to do a new backup afterwards (when this is released in a new version).
If a old backup - that was created before these changes took effect - should be imported, it has to be done in an old version of the app and then the app needs to be updated.

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

@sonarcloud
Copy link

sonarcloud bot commented Mar 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@litetex litetex changed the title Use JSON serialization Use JSON serialization for settings Mar 5, 2023
@litetex litetex marked this pull request as ready for review March 5, 2023 15:44
@SameenAhnaf SameenAhnaf added bug Issue is related to a bug database Issue is related to database operations labels May 13, 2023
@eloyesp
Copy link

eloyesp commented Jul 10, 2023

Hi, just found this issue and I want to add my two cents here.

I've just recovered newpipe after an android upgrade and faced that the android backup is not working on Android 13, so I have the backup on my PC, with the data, but I cannot use that to recover the state.

I found that the import/export functionality exported a zip file (great), and there are two files there, the database and the settings. I have the database because it was on the backup, but the settings were serialized differently, they are stored as an XML on the data folder and as some Java Serialization on the export.

Now you change that from Java-Serialization to JSON, ok, that might be more readable, but why to backup with a different format at all? Why not zip the XML settings file as is?

So the backup should be stored on the export zip as org.schabi.newpipe_preferences.xml.

Thanks.

@Angelk90

This comment was marked as off-topic.

@lm41
Copy link

lm41 commented Oct 14, 2023

If I may give some thoughts: It would be much more user friendly if there is still (maybe in a transition period) the possibility to import the old backups. If you want to load an old newpipe backup in a newer version and have to uninstall the app first and install an old version, this is in my opinion not the best solution, if not no solution at all.

Comment on lines +18 to +20
private static ObjectMapper newMapper() {
return new ObjectMapper();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Phind an ObjectMappershould be reused, because it's creation is relativly expensive.

SO source: https://stackoverflow.com/a/57671444

It kind of makes sense to me because in the spring boot world you have one instance of it and use it for all http requests unless specific config is required

Comment on lines +25 to +27
} catch (final IOException ioe) {
throw new UncheckedIOException(ioe);
}
Copy link
Collaborator

@XiangRongLin XiangRongLin Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to wrap it in UncheckedIOException?

It seems that exception is used in the stream API and ideally one should also throw it for stream related stuff.
https://stackoverflow.com/a/23402640

@Profpatsch
Copy link
Contributor

⚠️ Note that after merging this PR importing of existing settings won't work, due to the new format!
It's highly recommended to do a new backup afterwards (when this is released in a new version).

As a user, I’d expect settings import to continue working even for old formats. So even if the format is changed, I do not believe the deserializer of the old format should go away. Only the serializer.

@Stypox
Copy link
Member

Stypox commented Mar 28, 2024

Will be taken care of separately

@Stypox Stypox closed this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is related to a bug database Issue is related to database operations
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants