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

Feat: Added OptimizelyJson class to support GetFeatureVariableJson #214

Merged
merged 17 commits into from
May 11, 2020

Conversation

mnoman09
Copy link
Contributor

@mnoman09 mnoman09 commented May 4, 2020

Summary

  • Implementing OptimizelyJSON object and its API's needed to support json access for new public SDK API's

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

first pass. please address.

logger.Log(LogLevel.ERROR, ex.Message);
}
}
public OptimizelyJson(Dictionary<string, object> payload, ILogger logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

dict

{
try
{
Dict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't Deserialize here.

Copy link
Contributor

Choose a reason for hiding this comment

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

But check in other SDKs, if string is not valid, what's the behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

If Deserializing here, there should be no reference of Jobect inside Dict.


public Dictionary<string, object> ToDictionary()
{
return Dict;
Copy link
Contributor

Choose a reason for hiding this comment

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

Before returning it, Convert all JObjects, JArrays ... to IList and IDictionary.

@mnoman09 mnoman09 removed their assignment May 6, 2020
@mnoman09 mnoman09 requested a review from msohailhussain May 6, 2020 15:51
Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

Please do requested changes. I have seen variables are declared as Pascal case, it should be camel case inside method.
Second thing, instead of manually asserted every field, use TestData.CompareObject.
Third thing, I have added a test case, please complete that.
Once it's done, it's lgtm.

return default(T);
}

private T GetObject<T>(object o)
Copy link
Contributor

Choose a reason for hiding this comment

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

this approach doesn't look good to me. Second thing, if we really need to check. use

as instead of catching exception and doing nothing.
Revise this method.

{
try
{
return (T)o;
Copy link
Contributor

Choose a reason for hiding this comment

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

   (T)o
} else {
 ...
}```

@mnoman09 mnoman09 requested a review from msohailhussain May 7, 2020 13:22
Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

LGTM! Great work

Copy link

@pawels-optimizely pawels-optimizely left a comment

Choose a reason for hiding this comment

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

please add these quick tests for getValue:

  1. jsonPath: "field4." - invalid path
  2. jsonPath: "field4..inner_field1" - invalid path
  3. check if the object is not modified: for that call getValue twice with the valid non empty json path ( "field4.inner_field1" will do)

otherwise it looks good.

{
var payload = "{ \"field1\" : {\"1\":\"Csharp\",\"2\":\"Java\"} }";
var optimizelyJSONUsingString = new OptimizelyJson(payload, ErrorHandlerMock.Object, LoggerMock.Object);
var expectedValue = optimizelyJSONUsingString.GetValue<Dictionary<float, string>>("field1");

Choose a reason for hiding this comment

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

shouldn't it be <string, string> instead of <float, string> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, Actually it's to test that when invalid type is passed in getValue it will return default value.

@mnoman09 mnoman09 requested a review from pawels-optimizely May 8, 2020 14:41
Copy link

@pawels-optimizely pawels-optimizely left a comment

Choose a reason for hiding this comment

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

lgtm

@mikeproeng37 mikeproeng37 merged commit 22045d6 into master May 11, 2020
@msohailhussain msohailhussain deleted the mnoman/optimizelyJson branch January 5, 2021 20:43
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.

6 participants