-
Notifications
You must be signed in to change notification settings - Fork 3
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 #3 from alex-cova/teenyJson
Teeny json suport
- Loading branch information
Showing
36 changed files
with
3,557 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ on: | |
pull_request: | ||
types: [ opened, synchronize, reopened ] | ||
|
||
env: | ||
AZURE_BLOB_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
@@ -25,6 +28,7 @@ jobs: | |
run: mvn --batch-mode -DskipTests package | ||
|
||
- name: Test | ||
timeout-minutes: 5 | ||
run: mvn --batch-mode -Dmaven.test.failure.ignore=true test | ||
|
||
- name: Report | ||
|
@@ -38,6 +42,7 @@ jobs: | |
|
||
- name: Upload to Azure Blob Storage | ||
uses: bacongobbler/[email protected] | ||
if: env.AZURE_BLOB_STORAGE_CONNECTION_STRING != null | ||
with: | ||
source_dir: 'target/apidocs' | ||
container_name: '$web' | ||
|
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
98 changes: 98 additions & 0 deletions
98
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ParameterizedTypeHelper.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,98 @@ | ||
package net.jonathangiles.tools.teenyhttpd.implementation; | ||
|
||
import java.lang.reflect.Type; | ||
import java.lang.reflect.WildcardType; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
/** A helper class to hold the type arguments of a parameterized type and provide some utility methods. */ | ||
public final class ParameterizedTypeHelper implements Type { | ||
private final Class<?> firstType; | ||
private final Class<?> parentType;//nullable | ||
private final Type[] typeArguments; | ||
|
||
public ParameterizedTypeHelper(Class<?> firstType, Class<?> parentType) { | ||
this.firstType = firstType; | ||
this.parentType = parentType; | ||
this.typeArguments = null; | ||
} | ||
|
||
ParameterizedTypeHelper(Class<?> parentType, Type[] arguments) { | ||
this.firstType = getRealClass(arguments[0]); | ||
this.parentType = parentType; | ||
this.typeArguments = arguments; | ||
} | ||
|
||
/** | ||
* Returns the real class of the given type. | ||
* | ||
* @param type the type to get the real class of | ||
* @return the real class of the given type | ||
*/ | ||
private Class<?> getRealClass(Type type) { | ||
if (type instanceof WildcardType) { | ||
WildcardType wildcardType = (WildcardType) type; | ||
return (Class<?>) wildcardType.getUpperBounds()[0]; | ||
} | ||
|
||
return (Class<?>) type; | ||
} | ||
|
||
/** | ||
* Returns a new instance of ParameterizedTypeHelper with the given first type. | ||
* | ||
* @param firstType the first type | ||
* @return a new instance of ParameterizedTypeHelper | ||
*/ | ||
public ParameterizedTypeHelper withFirstType(Class<?> firstType) { | ||
if (typeArguments == null) { | ||
return new ParameterizedTypeHelper(firstType, parentType); | ||
} | ||
|
||
Type[] args = new Type[typeArguments.length]; | ||
|
||
args[0] = firstType; | ||
System.arraycopy(typeArguments, 1, args, 1, typeArguments.length - 1); | ||
|
||
return new ParameterizedTypeHelper(parentType, args); | ||
} | ||
|
||
@Override | ||
public String getTypeName() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
public boolean isParentTypeOf(Class<?> type) { | ||
return parentType != null && type.isAssignableFrom(parentType); | ||
} | ||
|
||
public Type[] getTypeArguments() { | ||
return typeArguments; | ||
} | ||
|
||
public Class<?> getFirstType() { | ||
return firstType; | ||
} | ||
|
||
/** | ||
* @return the second type of the parameterized type | ||
* @throws NullPointerException if the type is not a ParameterizedType | ||
*/ | ||
public Class<?> getSecondType() { | ||
Objects.requireNonNull(typeArguments, "Type is not a ParameterizedType"); | ||
return getRealClass(typeArguments[1]); | ||
} | ||
|
||
public Class<?> getParentType() { | ||
return parentType; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ParameterizedTypeHelper{" + | ||
"firstType=" + firstType + | ||
", parentType=" + parentType + | ||
", typeArguments=" + Arrays.toString(typeArguments) + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.