Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java arraylist and velocity arraylist behave differently #27

Open
developer-sunnywu opened this issue Apr 25, 2024 · 2 comments
Open

Java arraylist and velocity arraylist behave differently #27

developer-sunnywu opened this issue Apr 25, 2024 · 2 comments

Comments

@developer-sunnywu
Copy link

developer-sunnywu commented Apr 25, 2024

Description:

I try to use custom function return arraylist and here is my function in java


    private static Map<String, List<String>> map = Map.of(
            "Long", Arrays.asList("null", "1", "2"),
            "Boolean", Arrays.asList("null", "True", "False"),
            "BigDecimal", Arrays.asList("null", "BigDecimal.ZERO", "BigDecimal.ONE"),
            "LocalTime", Arrays.asList("null", "LocalTime.of(0, 0, 0)", "LocalTime.of(1, 1, 1)")
    );

    public static ArrayList<String> getValuesByFieldName(String filedName) {
        return new ArrayList<>(map.get(filedName));
    }
}

And there is my velocity.vm

#set($FieldUtil = $loader.loadClass("com.example.codegenerator.telosys.util.FieldUtil"))
#set($myJavaList = $FieldUtil.getValuesByFieldName('Long'))
$myJavaList.class.name
$myJavaList
### Will throw no attribute '['
$myJavaList[0]


#set( $mylist = [1, 2, 3, "A", true, 65.78] )
$mylist.class.name
$mylist
### It is okay here
$mylist[0]

I find that even though they have same type(java.util.ArrayList), the myJavaList not work

Version use: telosys-cli-4.1.1-001

Expected behaviour
I expect they can both use the same operator which I can access the element using bracket notation here. Hope I specify the problem clearly

@l-gu
Copy link
Member

l-gu commented Apr 29, 2024

You don't need a Java class for that
You can just use a map of lists with Velocity language
See https://doc.telosys.org/templates/code-snippets#maps-of-lists

@developer-sunnywu
Copy link
Author

Thank you! I will try your suggested solution. But the problem here we should expect they have same behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants