-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't Deserialize here.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
OptimizelySDK/OptimizelyJson.cs
Outdated
{ | ||
try | ||
{ | ||
return (T)o; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(T)o
} else {
...
}```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work
There was a problem hiding this 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:
- jsonPath: "field4." - invalid path
- jsonPath: "field4..inner_field1" - invalid path
- 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"); |
There was a problem hiding this comment.
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> ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Summary