-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Properly handle char and Character parameter types in JAX-RS methods
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 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
26 changes: 26 additions & 0 deletions
26
...ava/org/jboss/resteasy/reactive/server/core/parameters/converters/CharParamConverter.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,26 @@ | ||
package org.jboss.resteasy.reactive.server.core.parameters.converters; | ||
|
||
public class CharParamConverter implements ParameterConverter { | ||
|
||
@Override | ||
public Object convert(Object parameter) { | ||
String str = parameter.toString(); | ||
if (str.length() != 1) { | ||
throw new IllegalArgumentException("invalid char value: " + str); | ||
} | ||
return str.charAt(0); | ||
} | ||
|
||
public static class Supplier implements ParameterConverterSupplier { | ||
|
||
@Override | ||
public String getClassName() { | ||
return CharParamConverter.class.getName(); | ||
} | ||
|
||
@Override | ||
public CharParamConverter get() { | ||
return new CharParamConverter(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...rg/jboss/resteasy/reactive/server/core/parameters/converters/CharacterParamConverter.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,26 @@ | ||
package org.jboss.resteasy.reactive.server.core.parameters.converters; | ||
|
||
public class CharacterParamConverter implements ParameterConverter { | ||
|
||
@Override | ||
public Object convert(Object parameter) { | ||
String str = parameter.toString(); | ||
if (str.length() != 1) { | ||
throw new IllegalArgumentException("invalid Character value: " + str); | ||
} | ||
return Character.valueOf(str.charAt(0)); | ||
} | ||
|
||
public static class Supplier implements ParameterConverterSupplier { | ||
|
||
@Override | ||
public String getClassName() { | ||
return CharacterParamConverter.class.getName(); | ||
} | ||
|
||
@Override | ||
public CharacterParamConverter get() { | ||
return new CharacterParamConverter(); | ||
} | ||
} | ||
} |
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