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

Added missing Type Adaper for RestartArguments.arguments #618

Merged
merged 1 commit into from
May 17, 2022

Conversation

cdietrich
Copy link
Contributor

Added missing Type Adaper for RestartArguments.arguments

@cdietrich cdietrich added this to the v0.13.0 milestone May 13, 2022
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!ELEMENT_TYPE.equals(type))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this correct. without it will stackoverflow

public class RestartArgumentsTypeAdapterFactoryTest {

@Test
public void test() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a better way to test such things?

@cdietrich cdietrich force-pushed the cd_missingTypeAdapter branch 4 times, most recently from aef219e to 40b8263 Compare May 14, 2022 05:02
@cdietrich cdietrich requested a review from pisv May 17, 2022 13:05
@pisv
Copy link
Contributor

pisv commented May 17, 2022

LGTM, with just a few marginal notes:

  • Names of existing type adapter factories in org.eclipse.lsp4j.adapters end with Adapter rather than AdapterFactory. So it seems more appropriate to name this class RestartArgumentsTypeAdapter to match the already established naming convention, although the name RestartArgumentsTypeAdapterFactory might be more correct from the technical point of view.

  • The test case looks fine to me. Note that this is the first test case for type adapter factories in LSP4J, so there are currently no established convention on how to test such things.

  • I think the check ELEMENT_TYPE.equals(type) is correct and is necessary if the type adapter factory is registered globally with GsonBuilder (as done in the test case).

    Existing type adapter factories, which miss this check, don't have the mentioned problem with stackoverlow only because they are never registered globally, but are targeted precisely via annotations.

    It would probably be good to also add this check to existing type adapter factories to make the code more tolerant to usage in different contexts.

@cdietrich
Copy link
Contributor Author

renamed the class. i wonder how to test with the annotation thing instead of register globally

@pisv
Copy link
Contributor

pisv commented May 17, 2022

So far, we did not have specific unit tests for type adapter factories. Rather, there are sort of 'integration' tests for parsing/serializing protocol messages like DebugMessageJsonHandlerTest.

@cdietrich
Copy link
Contributor Author

@pisv i adapted the test to test the annotated type.
now if would work without the type check
should i remove it?

@pisv
Copy link
Contributor

pisv commented May 17, 2022

I would suggest removing the check now for uniformity sake, and adding it later to all existing type adapter factories if/when the need arises. Just my 2c.

@pisv
Copy link
Contributor

pisv commented May 17, 2022

Perhaps the test case could be slightly improved by using assertEquals and comparing the deserialized object with the expected value.

@cdietrich
Copy link
Contributor Author

done

@cdietrich
Copy link
Contributor Author

created #623 as follow up

@cdietrich cdietrich merged commit 69890e1 into main May 17, 2022
@cdietrich cdietrich deleted the cd_missingTypeAdapter branch May 17, 2022 15:52
@KamasamaK KamasamaK mentioned this pull request Sep 13, 2022
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