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

Invalid 'customTypeMapping' format: string> #986

Open
FunctionalHacker opened this issue May 12, 2023 · 4 comments · May be fixed by #1072
Open

Invalid 'customTypeMapping' format: string> #986

FunctionalHacker opened this issue May 12, 2023 · 4 comments · May be fixed by #1072

Comments

@FunctionalHacker
Copy link

FunctionalHacker commented May 12, 2023

Hi, I'm trying to map all instances of java.util.collection<MyClass> to Record<string,string> and I'm encountering this error

Execution generate of goal cz.habarta.typescript-generator:typescript-generator-maven-plugin:3.2.1263:generate failed: Invalid 'customTypeMapping' format: string>

My configuration

<configuration>
    <customTypeMappings>
        java.util.Collection&lt;MyClass&gt;:Record&lt;string,string&gt;
    </customTypeMappings>
</configuration>

I also tried the alternative syntax

<configuration>
    <customTypeMappings>
        java.util.Collection[MyClass]:Record[string,string]
    </customTypeMappings>
</configuration>

Also tried with Map

<configuration>
    <customTypeMappings>
        java.util.Collection[MyClass]:Map[string,string]
    </customTypeMappings>
</configuration>

The only thing I've gotten to work is mapping it to string in TypeScript

<configuration>
    <customTypeMappings>
        java.util.Collection[MyClass]:string
    </customTypeMappings>
</configuration>
@manoelcampos
Copy link

manoelcampos commented Oct 29, 2024

I have a similar issue.
If we have multiple levels of generic type parameters, it doesn't work.
For instance, I have a Java type such as Supplier<List<Double>> and want to convert it to a TypeScript function that returns an array of number () => number[], the configuration should be:

<customTypeMapping>java.util.function.Supplier[List[Double]]:() => number[]</customTypeMapping>

but I get the error "Execution generate of goal cz.habarta.typescript-generator:typescript-generator-maven-plugin:3.2.1263:generate failed: Failed to parse configured custom type mapping 'java.util.function.Supplier[List[Double]]:() => number[]': java.lang.ClassNotFoundException: java.util.function.Supplier[List[Double]]".

It just works if I only include one level of generic parameters:

<customTypeMapping>java.util.function.Supplier[List]:() => number[]</customTypeMapping>

Using version 3.2.1263.

@manoelcampos
Copy link

manoelcampos commented Oct 29, 2024

Using &lt; and &gt; instead of < and > also works in pom.xml maven project file, but only for one generic level:

<customTypeMapping>java.util.function.Supplier&lt;List&gt;:() => number[]</customTypeMapping>

When trying to include the complete type:

<customTypeMapping>java.util.function.Supplier&lt;List&lt;Double&gt;&gt;:() => number[]</customTypeMapping>

I get a similar error:

Execution generate of goal cz.habarta.typescript-generator:typescript-generator-maven-plugin:3.2.1263:generate failed: Failed to parse configured custom type mapping 'java.util.function.Supplier<List>:() => number[]': java.lang.ClassNotFoundException: java.util.function.Supplier<List>.

However, this time it recognizes the < and > characters (instead of showing [ and ]).

@manoelcampos
Copy link

And I found another issue.
If we have only one level of generic parameters, the typescript file is generated, but incorrectly.

Consider I want to map every List<Product> type in Java to a ProductDTO[] in typescript. I can configure the plugin like below:

<customTypeMappings>java.util.List[Product]:ProductDTO[]</customTypeMappings>

However, it ignores the generic type parameter (Product) and replaces all Lists by a ProductDTO[].
Lists of any type will be mapped to the same ProductDTO[].
For instance, List<Double>, List<String>, List<Product> are all amped to ProductDTO[].

@manoelcampos manoelcampos linked a pull request Nov 9, 2024 that will close this issue
@manoelcampos
Copy link

Hey @FunctionalHacker and @vojtechhabarta

I've just sent the PR #1072, which is a proposal to fix the issues reported here.
If you guys could check it and give me a feedback, I'd appreciate it.
I'm needing this fix too.

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 a pull request may close this issue.

2 participants