Skip to content

Conversation

@pandeymangg
Copy link
Contributor

@pandeymangg pandeymangg commented May 16, 2025

This pull request introduces several changes to improve the functionality and maintainability of the Formbricks Android SDK. The most important updates include replacing the use of id with name in ActionClassReference, adding a custom deserializer for SegmentFilterResource, and updating the Gson configuration in SurveyManager. Additionally, minor cleanup and configuration updates were made.

Functional Improvements:

  • Switch from id to name for ActionClassReference: Updated ActionClassReference to use name instead of id, and adjusted related logic in FormbricksInstrumentedTest to reflect this change. ([[1]](https://github.com/formbricks/android/pull/17/files#diff-17f9055fd2a7b5b3d60e0cfbdc2bb867b9dc7d837fedbcdbe016425973c92fe7L8), [[2]](https://github.com/formbricks/android/pull/17/files#diff-d8025fc041721bf9548c55167b39fa47fc3ba369cdd762cfc3727d5e98692e48L128-R128))

  • Custom Gson deserializer for SegmentFilterResource: Added SegmentFilterResourceDeserializer to handle both array and object JSON formats for SegmentFilterResource. ([android/src/main/java/com/formbricks/android/model/environment/SegmentFilterResourceDeserializer.ktR1-R25](https://github.com/formbricks/android/pull/17/files#diff-2f2cce680af0452e17e17d7821df2443867e87ccedd708117869d35cef84fe27R1-R25))

  • Gson configuration in SurveyManager: Introduced a centralized Gson instance in SurveyManager with the custom deserializer registered, replacing the default Gson usage. ([[1]](https://github.com/formbricks/android/pull/17/files#diff-bde2d5dbfa308a53395144d54ecc66f60c7665cf2b93c72e33221ae025969f60R42-R51), [[2]](https://github.com/formbricks/android/pull/17/files#diff-bde2d5dbfa308a53395144d54ecc66f60c7665cf2b93c72e33221ae025969f60L60-R73))

Cleanup and Configuration:

  • Removed unused imports: Cleaned up unused imports in SurveyManagerInstrumentedTest to improve readability. ([android/src/androidTest/java/com/formbricks/android/manager/SurveyManagerInstrumentedTest.ktL4-L12](https://github.com/formbricks/android/pull/17/files#diff-cde270f86fb07a8e127a02282a62efa7c15d47729e3530fafd3edd6784d101aaL4-L12))

  • Updated sonar exclusions: Added Network/FormbricksService.kt to the list of files excluded from SonarQube coverage analysis. ([sonar-project.propertiesR28](https://github.com/formbricks/android/pull/17/files#diff-43ed9d31bea2a6d518d69836bcd1a8e6bd81bf4df96c4745792c220ca5aa549cR28))

Summary by CodeRabbit

  • New Features
    • Improved support for advanced survey filtering by enabling polymorphic deserialization of segment filters.
  • Bug Fixes
    • Updated survey action matching to use action names instead of IDs for better reliability.
  • Chores
    • Excluded a specific network service file from code coverage analysis.
    • Removed unused imports in test files.
  • Refactor
    • Simplified action class references by removing unused ID fields and retaining only the name property.

@pandeymangg pandeymangg requested review from Copilot and mattinannt May 16, 2025 09:58
@coderabbitai
Copy link

coderabbitai bot commented May 16, 2025

Walkthrough

The changes update test logic to match action classes by name instead of ID, remove unused imports, and refactor deserialization in the SurveyManager to use a custom Gson instance with a new SegmentFilterResourceDeserializer. The ActionClassReference data class drops its id property. A new deserializer class is introduced, and a file is excluded from SonarQube coverage.

Changes

File(s) Change Summary
android/src/androidTest/java/com/formbricks/android/FormbricksInstrumentedTest.kt Modified test logic to match action classes by name property instead of id.
android/src/androidTest/java/com/formbricks/android/manager/SurveyManagerInstrumentedTest.kt Removed unused import statements.
android/src/main/java/com/formbricks/android/manager/SurveyManager.kt Introduced a custom Gson instance with SegmentFilterResourceDeserializer for deserialization; added gson property.
android/src/main/java/com/formbricks/android/model/environment/ActionClassReference.kt Removed the id property from the ActionClassReference data class, leaving only the name property.
android/src/main/java/com/formbricks/android/model/environment/SegmentFilterResourceDeserializer.kt Added new class SegmentFilterResourceDeserializer for polymorphic JSON deserialization of SegmentFilterResource.
sonar-project.properties Added **/network/FormbricksService.kt to SonarQube coverage exclusions.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b3e103 and 6354927.

📒 Files selected for processing (1)
  • sonar-project.properties (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sonar-project.properties
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (java-kotlin)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the Formbricks Android SDK by updating type usage and tests for better consistency and maintainability. Key changes include:

  • Replacing the use of the "id" field with "name" in ActionClassReference and updating corresponding test comparisons.
  • Introducing a custom Gson deserializer (SegmentFilterResourceDeserializer) to handle varied JSON formats for SegmentFilterResource.
  • Centralizing Gson configuration in SurveyManager and performing cleanup in tests and configuration files.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sonar-project.properties Added exclusion for Network/FormbricksService.kt to SonarQube checks.
SegmentFilterResourceDeserializer.kt Added a custom deserializer to support both array and object JSON formats.
ActionClassReference.kt Removed the "id" property and switched to using "name" for actions.
SurveyManager.kt Centralized Gson instantiation with custom deserializer registration.
SurveyManagerInstrumentedTest.kt Removed unused imports to improve readability.
FormbricksInstrumentedTest.kt Updated test logic to compare action class references by "name" instead of "id".

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
android/src/main/java/com/formbricks/android/manager/SurveyManager.kt (1)

85-85: Consider using the same Gson instance for serialization

While using the default Gson instance for serialization will work, it would be more consistent to use the same custom Gson instance for both serialization and deserialization.

- environmentDataHolderJson = Gson().toJson(value)
+ environmentDataHolderJson = gson.toJson(value)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0a4445 and 6b3e103.

📒 Files selected for processing (6)
  • android/src/androidTest/java/com/formbricks/android/FormbricksInstrumentedTest.kt (1 hunks)
  • android/src/androidTest/java/com/formbricks/android/manager/SurveyManagerInstrumentedTest.kt (0 hunks)
  • android/src/main/java/com/formbricks/android/manager/SurveyManager.kt (3 hunks)
  • android/src/main/java/com/formbricks/android/model/environment/ActionClassReference.kt (0 hunks)
  • android/src/main/java/com/formbricks/android/model/environment/SegmentFilterResourceDeserializer.kt (1 hunks)
  • sonar-project.properties (1 hunks)
💤 Files with no reviewable changes (2)
  • android/src/androidTest/java/com/formbricks/android/manager/SurveyManagerInstrumentedTest.kt
  • android/src/main/java/com/formbricks/android/model/environment/ActionClassReference.kt
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (6)
android/src/main/java/com/formbricks/android/model/environment/SegmentFilterResourceDeserializer.kt (2)

7-25: Well-structured polymorphic deserializer implementation

This deserialization approach elegantly handles the polymorphic nature of SegmentFilterResource by determining the appropriate type based on the JSON structure. The conditional logic clearly distinguishes between array (Group) and object (Primitive) cases.


15-22:

Details

✅ Verification successful

Verify TypeToken usage

The TypeToken approach works well for deserializing generic collections, but ensure that the class hierarchy of SegmentFilterResource, SegmentFilter, and SegmentPrimitiveFilter properly supports this deserialization pattern.


🏁 Script executed:

#!/bin/bash
# Look for the SegmentFilterResource class definition to confirm the class hierarchy
fd -t f --exec grep -A 20 "sealed class SegmentFilterResource" {} \;

Length of output: 1107


🏁 Script executed:

#!/bin/bash
# Search for all uses of Gson’s TypeToken to locate the deserializer and see its context
rg -n "TypeToken" -C 5

Length of output: 2884


🏁 Script executed:

#!/bin/bash
# Search for the definition of SegmentFilter in the codebase
rg -n "sealed class SegmentFilter" -C 5
rg -n "interface SegmentFilter" -C 5
rg -n "class SegmentFilter" -C 5

Length of output: 11209


TypeToken usage verified

GSON’s TypeToken<List<SegmentFilter>> correctly resolves the generic List<SegmentFilter>, and since SegmentFilter and SegmentPrimitiveFilter are concrete data classes in the same package, the custom JsonDeserializer wraps them into SegmentFilterResource as intended—no further changes needed.

android/src/androidTest/java/com/formbricks/android/FormbricksInstrumentedTest.kt (1)

128-128: Correctly updated action class matching from ID to name

The code has been appropriately updated to use name instead of id for matching action classes, which aligns with the removal of the id property from the ActionClassReference data class.

android/src/main/java/com/formbricks/android/manager/SurveyManager.kt (3)

10-12: Appropriate imports added

New imports for SegmentFilterResource and SegmentFilterResourceDeserializer support the centralized Gson instance implementation.


42-49: Good implementation of centralized Gson instance

Creating a single Gson instance with the custom deserializer registered is an efficient approach. This implementation properly handles the polymorphic nature of SegmentFilterResource.


73-73: Now using custom Gson instance for deserialization

The code correctly uses the custom Gson instance with the registered deserializer when parsing the JSON string from shared preferences.

@sonarqubecloud
Copy link

@mattinannt mattinannt added this pull request to the merge queue May 16, 2025
Merged via the queue into main with commit 4d75467 May 16, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants