-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #543 from SentryMan/genericIssue
Fix JsonB generic generation errors
- Loading branch information
Showing
5 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
http-generator-core/src/test/java/io/avaje/http/generator/core/JsonBUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.avaje.http.generator.core; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.StringWriter; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class JsonBUtilTest { | ||
|
||
@Test | ||
void writeType() { | ||
UType uType = UType.parse("my.pack.Foo"); | ||
var sw = new StringWriter(); | ||
JsonBUtil.writeType(uType, new Append(sw)); | ||
|
||
assertThat(sw.toString()).isEqualTo("Foo.class)"); | ||
} | ||
|
||
@Test | ||
void writeType_generic() { | ||
UType uType = UType.parse("my.pack.Some<java.lang.String>"); | ||
var sw = new StringWriter(); | ||
JsonBUtil.writeType(uType, new Append(sw)); | ||
|
||
assertThat(sw.toString()).isEqualTo("Types.newParameterizedType(Some.class, String.class))"); | ||
} | ||
|
||
@Test | ||
void writeType_genericWithWildcard() { | ||
UType uType = UType.parse("my.pack.Some<java.lang.String, ?>"); | ||
var sw = new StringWriter(); | ||
JsonBUtil.writeType(uType, new Append(sw)); | ||
|
||
assertThat(sw.toString()).isEqualTo("Types.newParameterizedType(Some.class, String.class, Object.class))"); | ||
} | ||
|
||
@Test | ||
void writeType_genericWithMultiple() { | ||
UType uType = UType.parse("my.pack.Some<java.lang.String, my.other.Foo>"); | ||
var sw = new StringWriter(); | ||
JsonBUtil.writeType(uType, new Append(sw)); | ||
|
||
assertThat(sw.toString()).isEqualTo("Types.newParameterizedType(Some.class, String.class, Foo.class))"); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/test-javalin-jsonb/src/main/java/org/example/myapp/web/test/GenericController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.example.myapp.web.test; | ||
|
||
import io.avaje.http.api.Controller; | ||
import io.avaje.http.api.Get; | ||
import io.avaje.http.api.Path; | ||
import io.avaje.jsonb.Json; | ||
|
||
@Path("/jsonbGeneric") | ||
@Controller | ||
public class GenericController { | ||
|
||
@Json | ||
public static class Data<T> {} | ||
|
||
@Json | ||
public static class Data2<T, T2> {} | ||
|
||
@Get("single") | ||
Data<String> getData() { | ||
return null; | ||
} | ||
|
||
@Get("double") | ||
Data2<String, ?> getData2() { | ||
return null; | ||
} | ||
} |