[GitHub] [cxf] reta opened a new pull request #677: CXF-8296: Custom Boolean ParamConverter wrong behaviour

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] reta opened a new pull request #677: CXF-8296: Custom Boolean ParamConverter wrong behaviour

GitBox

reta opened a new pull request #677:
URL: https://github.com/apache/cxf/pull/677


   The general issue is with the way CXF handles `null` parameter values injection, it does not actually distinguish if the converter was applied and returned `null`, or the result is just `null` for any reason (no converter found fe).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] andymc12 commented on a change in pull request #677: CXF-8296: Custom Boolean ParamConverter wrong behaviour

GitBox

andymc12 commented on a change in pull request #677:
URL: https://github.com/apache/cxf/pull/677#discussion_r436694266



##########
File path: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
##########
@@ -539,21 +547,32 @@ private static RuntimeException createParamConversionException(ParameterType pTy
         }
         return ExceptionUtils.toBadRequestException(ex, null);
     }
-    public static <T> T createFromParameterHandler(String value,
-                                                    Class<T> pClass,
-                                                    Type genericType,
-                                                    Annotation[] anns,
-                                                    Message message) {
-        T result = null;
+    
+    public static <T> Optional<ParamConverter<T>> getParamConverter(Class<T> pClass,
+            Type genericType, Annotation[] anns, Message message) {
+        
         if (message != null) {
             ServerProviderFactory pf = ServerProviderFactory.getInstance(message);
             ParamConverter<T> pm = pf.createParameterHandler(pClass, genericType, anns, message);
             if (pm != null) {
-                result = pm.fromString(value);
+                return Optional.of(pm);
             }
         }
-        return result;
+        
+        return Optional.empty();

Review comment:
       Minor suggestion - you could replace the if-check and this line with `return Optional.ofNullable(pm);`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] reta commented on a change in pull request #677: CXF-8296: Custom Boolean ParamConverter wrong behaviour

GitBox
In reply to this post by GitBox

reta commented on a change in pull request #677:
URL: https://github.com/apache/cxf/pull/677#discussion_r437072496



##########
File path: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
##########
@@ -539,21 +547,32 @@ private static RuntimeException createParamConversionException(ParameterType pTy
         }
         return ExceptionUtils.toBadRequestException(ex, null);
     }
-    public static <T> T createFromParameterHandler(String value,
-                                                    Class<T> pClass,
-                                                    Type genericType,
-                                                    Annotation[] anns,
-                                                    Message message) {
-        T result = null;
+    
+    public static <T> Optional<ParamConverter<T>> getParamConverter(Class<T> pClass,
+            Type genericType, Annotation[] anns, Message message) {
+        
         if (message != null) {
             ServerProviderFactory pf = ServerProviderFactory.getInstance(message);
             ParamConverter<T> pm = pf.createParameterHandler(pClass, genericType, anns, message);
             if (pm != null) {
-                result = pm.fromString(value);
+                return Optional.of(pm);
             }
         }
-        return result;
+        
+        return Optional.empty();

Review comment:
       Surely, less code, thanks @andymc12!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] reta merged pull request #677: CXF-8296: Custom Boolean ParamConverter wrong behaviour

GitBox
In reply to this post by GitBox

reta merged pull request #677:
URL: https://github.com/apache/cxf/pull/677


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]