You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Thomas Mortagne (JIRA)" <ji...@apache.org> on 2018/10/15 11:17:00 UTC

[jira] [Comment Edited] (VELOCITY-892) Method arguments conversions should be based on Type instead of Class

    [ https://issues.apache.org/jira/browse/VELOCITY-892?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16650084#comment-16650084 ] 

Thomas Mortagne edited comment on VELOCITY-892 at 10/15/18 11:16 AM:
---------------------------------------------------------------------

I'm not really talking about having two methods in the same class but simply having methods taking something else than List<String> or List as parameter.

Imagine the following use case:

{code}
    public void foo(List<Integer> parameter)
    {
        for (Integer value : parameter) {
            // do stuff with the integer
        }
    }
{code}

{code}
$obj.foo("1, 2, 3, 4, 5")
{code}

It's impossible for the converter to know it should convert each element of the list to Integer so at best you will write a converter which produce a List<String> and the method will crash with a ClassCastException.


was (Author: tmortagne):
I'm not really talking about having two methods in the same class but simply having methods taking something else than List<String> or List as parameter.

Imagine the following use case:

{quote}
    public void foo(List<Integer> parameter)
    {
        for (Integer value : parameter) {
            // do stuff with the integer
        }
    }
{quote}

{quote}
$obj.foo("1, 2, 3, 4, 5")
{quote}

It's impossible for the converter to know it should convert each element of the list to Integer so at best you will write a converter which produce a List<String> and the method will crash with a ClassCastException.

> Method arguments conversions should be based on Type instead of Class
> ---------------------------------------------------------------------
>
>                 Key: VELOCITY-892
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-892
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 2.0
>            Reporter: Thomas Mortagne
>            Priority: Major
>             Fix For: 2.0
>
>
> I was happy to see that method arguments conversion has been added to 2.0 so that I can remove the uberspector we have on XWiki side but unfortunately ConversionHandler is limited to classes which is way too restrictive for us (for example if the parameter type is List<String> it won't do the same thing than if the type is List<Integer>).
> Our uberspector can be found on https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/introspection/MethodArgumentsUberspector.java to see what we do exactly.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org