-
Notifications
You must be signed in to change notification settings - Fork 6
policy on deserializeImpl JSONValue #59
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
Conversation
|
For sure we need to figure out why put doesn't work. I don't want to have special cases here. Can you post the errors that occur? |
My fault. In deserializing JSONValue array, I should call deserializeImpl: case ArrayStart:
item.type = JSONType.Array;
item.array = null;
deserializeImpl(policy, tokenizer, item.array);
break;other than call deserializeArray directly. Thus item.put(newElem) works. I fixed it in the new commit. |
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.
In deserializing JSONValue array, I should call deserializeImpl
Ahh!!! ok, because deserializeImpl is the thing that decides to use Appender for deserializeArray.
OK, so let's standardize on calling deserializeImpl for all types. Even object.
And make sure to call it via policy.deserializeImpl(...) to give the policy a chance to intercept.
|
Nice work! |
|
I am thinking about adding maxDepth check into defaultDeserializePolicy. The problem is how to store the change of the depth? If we assign a field to store the depth in defaultDeserializePolicy then check and modify it in onXXXBegin() and onXXXEnd(), it looks like all the customized policies will also need to define the depth field. We couldn't provide a shim for them like relPol because relPol is constant while depth is changing. So it looks like it's not worthy to add maxDepth as official option into defaultDeserializePolicy. Users who want it could implement their own onXXXBegin() and onXXXEnd() with maxDepth check. |
You would add a shim in Something like auto onObjectBegin(JT, T)(ref JT tokenizer, ref T item) {
if(++depth > maxDepth)
throw new ex(...);
return .onObjectBegin(this, tokenizer, item);
}
void onObjectEnd(JT, T, C)(ref JT tokenizer, ref T item, ref C context) {
--depth;
.onObjectEnd(this, tokenizer, item, context);
}take a look at how the |
Thank you, I got it. I have done it in #62 |
When revising the JSONValue's deserializeImpl function, it looks like
in onArrayElement() can't handle JSONValue[]. Now the codes there are suggested by AI.