Support for data libraries (guava, joda, vavr) #545
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 addguava
mappings usingadditionalDataLibraries
parameter. Here is Maven example:Supported libraries are:
guava
(source) (definition)joda
(source) (definition)vavr
(source) (definition)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 exampleBigDecimal
andcom.google.common.primitives.UnsignedInteger
) orDate
(which matches also for example subclasses injava.sql
package). And also mapping forCalendar
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.