Skip to content

Abstraction for JSON object mapper #3319

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

Merged
merged 22 commits into from
Mar 15, 2023

Conversation

clebersonp
Copy link
Contributor

Framework created for redis json parser commands using abstraction for different json parser custom engines to achieve decoupling and programming code for interface instead of implementation.

Junit tests were written for the custom gson and jackson parser engine.

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2023

Codecov Report

Patch coverage: 86.95% and project coverage change: -0.07 ⚠️

Comparison is base (519faa3) 67.03% compared to head (c2af859) 66.96%.

❗ Current head c2af859 differs from pull request most recent head 4ab7b06. Consider uploading reports for the commit 4ab7b06 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3319      +/-   ##
============================================
- Coverage     67.03%   66.96%   -0.07%     
- Complexity     4656     4657       +1     
============================================
  Files           263      263              
  Lines         15061    15073      +12     
  Branches        949      949              
============================================
- Hits          10096    10094       -2     
- Misses         4560     4573      +13     
- Partials        405      406       +1     
Impacted Files Coverage Δ
...ava/redis/clients/jedis/MultiNodePipelineBase.java 21.06% <0.00%> (-0.05%) ⬇️
src/main/java/redis/clients/jedis/Pipeline.java 17.09% <0.00%> (-0.04%) ⬇️
...main/java/redis/clients/jedis/TransactionBase.java 11.29% <0.00%> (-0.03%) ⬇️
.../main/java/redis/clients/jedis/CommandObjects.java 85.30% <100.00%> (+0.04%) ⬆️
...rc/main/java/redis/clients/jedis/UnifiedJedis.java 74.77% <100.00%> (+0.15%) ⬆️
...s/clients/jedis/json/parser/DefaultGsonParser.java 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@sazzad16 sazzad16 left a comment

Choose a reason for hiding this comment

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

Thank you for addressing previous change requests. Here are more 🙂

@@ -34,6 +34,9 @@

public class CommandObjects {

// initialize the parser with simple gson configuration as the default.
private Optional<JsonParser> jsonParser = Optional.of(new DefaultGsonParser());
Copy link
Contributor

Choose a reason for hiding this comment

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

This invalidates #3223 where people may want to exclude Gson when they are not using RedisJSON commands.

We can do this in getJsonParser(). When it is called we can be sure that a RedisJSON command is requested and as no parser/mapper is set, we can go ahead for the default one. Note: We will need Double-checked locking.

image

@sazzad16 sazzad16 added this to the 4.4.0 milestone Mar 14, 2023
@clebersonp clebersonp requested a review from sazzad16 March 15, 2023 00:56
@sazzad16 sazzad16 changed the title Abstraction for json parser Abstraction for JSON object mapper Mar 15, 2023
@sazzad16 sazzad16 merged commit 538c656 into redis:master Mar 15, 2023
@sazzad16
Copy link
Contributor

Merged. Thank you @clebersonp for your contribution!

@clebersonp
Copy link
Contributor Author

@sazzad16, Thanks for your time and great suggestions. 👍 😄

banker added a commit to banker/jedis that referenced this pull request Mar 28, 2023
* Edited gson dependency as optional and add jackson dependency only for tests purpose

* Created exception for config error purpose

* Classes and interfaces created to gain code decoupling from json convertion implementation

* Class is no longer needed

* Interfaces created as contract for all redis command json operations to set an implementation of a json convertion by polymorphism

* Changed json engine implementation to an interface to decouple code and make it interchangeable

* Implemented contract to define a json engine encoding/decoding

* classes created for json conversion with different json engines for testing purposes and junit tests for them

* Removed import that is no longer used

* Removed the optional statement for gson lib to not break the change

* Just removed unused exception

* Edited to use a plain jedis exception instead of a custom one

* setting gson as default json parser automatically when none set

* Removed unnecessary interface but kept setters for json serializer/deserializer engine configuration

* Unused imports removed

* Classes, interfaces, methods and other comment references renamed from word 'parser' to 'object mapper'.

* Classes and interfaces moved to 'json' package because it's not need a separate package

* Made some tweaks to the custom object mapper for jackson which throws a jedi's Exception instead of just printing stack trace.

* Refactored method to get json object mapper reference using double checked lock approach as suggestion in review code

* Removed unit test no longer occurs jedis exception after refactoring json object mapper instance in 'command object class'

* Unused imports removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants