Velocity
  1. Velocity
  2. VELOCITY-538

Cannot add objects as values in Map creation unless last entry is quoted

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Windows XP Service pack 2, Sun JVM 1.5.0.11

      Description

      When creating a Map using the velocity 1.5 syntax (

      {key:value,...}

      ) it seems I can only add objects (except Strings) as map values if the last map entry is quoted. The following (where $object is put into context before, of course) will produce a parse exception:

      #set ($map =

      {"key": $object}

      )

      Where the following will not:

      #set ($map =

      {"key": $object, "anotherkey":"anothervalue"}

      )

      The "anotherkey": "anothervalue" entry does the trick in the form of "":"" as well, but something is up here. OR this is a map creation "flaw" not documented. Using the following will of course not get the desired result:

      #set ($map =

      {"key": "$object"}

      )

      since velocity will evaluate the $object reference and use its .toString() (where what you wanted to do was probably to add the actual object).

      Would appreciate comments that could indicate if my thinking here is flawed or if it actually is a bug.

        Activity

        Hide
        Will Glass-Husain added a comment -

        Fixed. Added syntax to test/templates/map.vm for automatic testing.

        Show
        Will Glass-Husain added a comment - Fixed. Added syntax to test/templates/map.vm for automatic testing.
        Hide
        Will Glass-Husain added a comment -

        More detail. The problem is the } character right after the $object.

        This doesn't work (parse error)
        #set ($map =

        {"key": $object}

        )

        and this does (note the spacing)

        #set ($map =

        {"key": $object }

        )

        Show
        Will Glass-Husain added a comment - More detail. The problem is the } character right after the $object. This doesn't work (parse error) #set ($map = {"key": $object} ) and this does (note the spacing) #set ($map = {"key": $object } )
        Hide
        Will Glass-Husain added a comment -

        thanks for reporting this. seems like a bug to me.

        Show
        Will Glass-Husain added a comment - thanks for reporting this. seems like a bug to me.

          People

          • Assignee:
            Will Glass-Husain
            Reporter:
            Asmodean
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development