Skip to content

Conversation

@gulugulubing
Copy link
Contributor

When revising the JSONValue's deserializeImpl function, it looks like

item.put(newElem);

in onArrayElement() can't handle JSONValue[]. Now the codes there are suggested by AI.

@schveiguy
Copy link
Owner

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?

@gulugulubing
Copy link
Contributor Author

gulugulubing commented Aug 20, 2025

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.

Copy link
Owner

@schveiguy schveiguy left a 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.

@gulugulubing gulugulubing requested a review from schveiguy August 20, 2025 20:49
@schveiguy schveiguy merged commit 4a0ae85 into schveiguy:master Aug 20, 2025
6 checks passed
@schveiguy
Copy link
Owner

Nice work!

@gulugulubing
Copy link
Contributor Author

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.

@schveiguy
Copy link
Owner

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.

You would add a shim in DefaultDeserializationPolicy just like onField, which calls the module. Notice how relPol is only used as a shim to deal with legacy code. This is a new concept, so we don't need that legacy.

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 onField hook works to implement the release after a member.

@gulugulubing
Copy link
Contributor Author

You would add a shim in DefaultDeserializationPolicy just like onField, which calls the module. Notice how relPol is only used as a shim to deal with legacy code. This is a new concept, so we don't need that legacy.

Thank you, I got it. I have done it in #62

@schveiguy schveiguy mentioned this pull request Sep 4, 2025
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.

2 participants