forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
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 quarkusio#30626 from Sgitario/30605
Fix support of primitive types for filtering in REST Data Panache
- Loading branch information
Showing
8 changed files
with
90 additions
and
19 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
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
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
45 changes: 45 additions & 0 deletions
45
...che/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/utils/TypeUtils.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,45 @@ | ||
package io.quarkus.rest.data.panache.deployment.utils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.quarkus.gizmo.Type; | ||
|
||
public final class TypeUtils { | ||
|
||
private static final Map<String, Class> PRIMITIVE_TO_CLASS_MAPPING = new HashMap<>(); | ||
|
||
static { | ||
PRIMITIVE_TO_CLASS_MAPPING.put("int", Integer.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("byte", Byte.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("char", Character.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("short", Short.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("long", Long.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("float", Float.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("double", Double.class); | ||
PRIMITIVE_TO_CLASS_MAPPING.put("boolean", Boolean.class); | ||
} | ||
|
||
private TypeUtils() { | ||
|
||
} | ||
|
||
public static Object primitiveToClass(String type) { | ||
Class<?> clazz = PRIMITIVE_TO_CLASS_MAPPING.get(type); | ||
return clazz != null ? clazz : type; | ||
} | ||
|
||
public static Type toGizmoType(Object object) { | ||
if (object instanceof Type) { | ||
return (Type) object; | ||
} else if (object instanceof String) { | ||
return Type.classType((String) object); | ||
} else if (object instanceof Class) { | ||
return Type.classType((Class<?>) object); | ||
} | ||
|
||
throw new IllegalArgumentException("Unsupported object of type " + object.getClass() | ||
+ ". Supported types are Type, String and Class"); | ||
} | ||
|
||
} |