Skip to content

Structure view #1541

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 5 commits into from
Apr 22, 2025
Merged

Structure view #1541

merged 5 commits into from
Apr 22, 2025

Conversation

BoykoAlex
Copy link
Contributor

  • Serialization for index elements via RuntimeTypeAdapterFactory borrowed from gson-extras
  • Initial implementation of the structure view in VSCode

@martinlippert
Copy link
Member

Two thoughts regarding the serialization changes:

  • this does not take the default value optimization into account that is in place for the annotations, injection points, and super types on the Bean object. The default deserialization of GSON doesn't invoke the constructor, so the default value objects are not set. Instead, there are many duplicates of these empty array objects being created at deserialization. Would be good if we could get the optimization to work for this implementation as well.

  • the mechanism seems to require that all subtypes of SpringIndexElement are "manually" registered in the createGSON method and I fear that we will forget that one day when creating a new index element type. Can we somehow avoid that or get at least a unit test in place that fails in such a situation? That would be awesome.

@BoykoAlex
Copy link
Contributor Author

Gson is rather simple... It serializes the fields and then uses the no args constructor and reflection to set the fields back. Therefore, the default values issues is a choice of having null field values and getter returning the default value if the value is null, special case is java.lang.Object in the list of supertypes... why don't we just get rid of java.lang.Object from the list? Any class would have java.lang.Object as the root anyway. If there are more cases of default values that I missed let me know please as it may change my line of thought for this case ;-) Otherwise, we'd have to bring back gson adapters for Bean and InjectionPoint... I'd rather attempt to handle all subtypes the same.

The "manual" registration of subtypes I think can be avoided with some changes I did to the RuntimeTypeAdapterFactory where subtypes can be registered as they are discovered... The downside is that we'd have to FQN rather than class simple name just like we had initially.

@BoykoAlex
Copy link
Contributor Author

@martinlippert Thus, no need to specifically state subclasses that can be serialized. Default values for empty array and collections via null field value but a getter able to return the default value in the case of the null field.
I have also attempted not to serialize java.lang.Object entry of supertypes... instead I had to add isInterface boolean field and build a set in getSupertypes for the case of a class type to add java.lang.Object to the resultant set.

@martinlippert
Copy link
Member

The serialization part looks good to me, like it very much.

@BoykoAlex BoykoAlex merged commit d886efd into main Apr 22, 2025
4 checks passed
@martinlippert martinlippert added this to the 4.31.0.RELEASE milestone Apr 23, 2025
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.

2 participants