-
Notifications
You must be signed in to change notification settings - Fork 14
(Javalin) Avaje JsonB support #99
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
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5cd1fc5
start
SentryMan ebdff93
create JsonB Util
SentryMan d64812f
support
SentryMan a370f37
this
SentryMan bac1d65
unstatic jsontype and primitive map
SentryMan f76600f
more this
SentryMan 4e69924
Merge remote-tracking branch 'upstream/master' into javalinJsonB
SentryMan e5f729e
javalin jsonB test
SentryMan 22e9491
something is up with JsonB
SentryMan 40c9da2
tests finally pass
SentryMan 854c2e1
last this
SentryMan d40a180
Update README.md
SentryMan a10dd13
release 11
SentryMan b052639
remove style
SentryMan 20267f4
Update ElementReader.java
SentryMan 64e9322
Update ElementReader.java
SentryMan 7329ca4
Update ElementReader.java
SentryMan cd21c92
Update JavalinProcessorTest.java
SentryMan 85d6f75
Update JavalinProcessorTest.java
SentryMan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -9,3 +9,5 @@ build/ | |
*.project | ||
*.processors | ||
*/bin/ | ||
*.editorconfig | ||
*.Module |
This file contains hidden or 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 hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
http-generator-core/src/main/java/io/avaje/http/generator/core/JsonBUtil.java
This file contains hidden or 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,63 @@ | ||
package io.avaje.http.generator.core; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public class JsonBUtil { | ||
private JsonBUtil() {} | ||
|
||
public static Map<String, UType> getJsonTypes(ControllerReader reader) { | ||
|
||
final Map<String, UType> jsonTypes = new LinkedHashMap<>(); | ||
|
||
final Consumer<UType> addToMap = uType -> jsonTypes.put(uType.full(), uType); | ||
|
||
reader.getMethods().stream() | ||
.filter(MethodReader::isWebMethod) | ||
.filter(m -> !"byte[]".equals(m.getReturnType().toString())) | ||
.filter(m -> m.getProduces() == null || m.getProduces().toLowerCase().contains("json")) | ||
.forEach( | ||
methodReader -> { | ||
addJsonBodyType(methodReader, addToMap); | ||
if (!methodReader.isVoid()) { | ||
addToMap.accept(UType.parse(methodReader.getReturnType())); | ||
} | ||
}); | ||
|
||
return Map.copyOf(jsonTypes); | ||
} | ||
|
||
private static void addJsonBodyType(MethodReader methodReader, Consumer<UType> addToMap) { | ||
if (methodReader.getBodyType() != null) { | ||
methodReader.getParams().stream() | ||
.filter(MethodParam::isBody) | ||
.map(MethodParam::getUType) | ||
.forEach(addToMap); | ||
} | ||
} | ||
|
||
public static void writeJsonbType(UType type, Append writer) { | ||
|
||
writer.append(" this.%sJsonType = jsonB.type(", type.shortName()); | ||
if (!type.isGeneric()) { | ||
writer.append("%s.class)", PrimitiveUtil.wrap(type.full())); | ||
} else { | ||
switch (type.mainType()) { | ||
case "java.util.List": | ||
writer.append("%s.class).list()", type.param0()); | ||
break; | ||
case "java.util.Set": | ||
writer.append("%s.class).set()", type.param0()); | ||
break; | ||
case "java.util.Map": | ||
writer.append("%s.class).map()", type.param1()); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException( | ||
"Only java.util Map, Set and List are supported JsonB Controller Collection Types"); | ||
} | ||
} | ||
writer.append(";").eol(); | ||
} | ||
} |
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
http-generator-core/src/main/java/io/avaje/http/generator/core/PrimitiveUtil.java
This file contains hidden or 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,24 @@ | ||
package io.avaje.http.generator.core; | ||
|
||
import java.util.Map; | ||
|
||
public final class PrimitiveUtil { | ||
|
||
private PrimitiveUtil() {} | ||
|
||
static final Map<String, String> wrapperMap = | ||
Map.of( | ||
"char", "Character", | ||
"byte", "Byte", | ||
"int", "Integer", | ||
"long", "Long", | ||
"short", "Short", | ||
"double", "Double", | ||
"float", "Float", | ||
"boolean", "Boolean"); | ||
|
||
public static String wrap(String shortName) { | ||
final var wrapped = wrapperMap.get(shortName); | ||
return wrapped != null ? wrapped : shortName; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to check this