Skip to content

Support for data libraries (guava, joda, vavr) #545

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 1 commit into from
Sep 28, 2020

Conversation

vojtechhabarta
Copy link
Owner

This is implementation of general mechanism for mapping certain Java types from supported library to TypeScript without modifying typescript-generator Java source code and adding dependency on supported library.

Let's first see how these libraries are supported in Jackson2. Jackson2 has concept of modules so for example for guava library there is a GuavaModule (in com.fasterxml.jackson.datatype:jackson-datatype-guava) that adds support for guava to Jackson2 by adding serializers and deserializers for certain guava data types.

To map those types correctly in typescript-generator previously it was needed to use customTypeMappings parameter to add mappings for needed types manually. Instead of this it is now possible to add guava mappings using additionalDataLibraries parameter. Here is Maven example:

<configuration>
    <jsonLibrary>jackson2</jsonLibrary>
    <additionalDataLibraries>
        <library>guava</library>
    </additionalDataLibraries>
    ...
</configuration>

Supported libraries are:

Note: typescript-generator doesn't have dependency on those libraries (except for tests) but it needs to load classes from libraries definitions to be able to also recognize their subclasses. So it relies on user project dependencies.

As mentioned this feature processes also subclasses which is different from customTypeMappings parameter that can't map subclasses (yet).

This PR also changes how built-in (known) types are handled. Previously there were individual mappings (without subclasses) whereas now there are mappings for supertypes like Number (which matches also for example BigDecimal and com.google.common.primitives.UnsignedInteger) or Date (which matches also for example subclasses in java.sql package). And also mapping for Calendar class was added.

This PR is related to #532 (Vavr support). Difference is that this PR doesn't require adding Vavr dependency. It also adds mapping for more Vavr data types.

This PR is also related to #435 (custom mappings of supertypes). It prepares some logic (subclasses, generics) for easier implementation.

@vojtechhabarta
Copy link
Owner Author

Released in v2.26.723.

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.

1 participant