You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Simone Tripodi (JIRA)" <ji...@apache.org> on 2013/01/23 11:16:13 UTC

[jira] [Created] (SLING-2712) ValueMap doesn't support primitive types

Simone Tripodi created SLING-2712:
-------------------------------------

             Summary: ValueMap doesn't support primitive types
                 Key: SLING-2712
                 URL: https://issues.apache.org/jira/browse/SLING-2712
             Project: Sling
          Issue Type: Improvement
          Components: JCR
    Affects Versions: JCR Resource 2.2.4
            Reporter: Simone Tripodi
             Fix For: JCR Resource 2.2.4


I have a {{Resource}} which has a property named {{releaseMonth}} which is of type {{long}}; then I have a simple {{NumberFormat}}

{code}
NumberFormat numberFormat = new DecimalFormat("00");
{code}

If I try to execute, in a JSP, the following code, to cast the {{releaseMonth}} property to the primitive {{long.class}}:

{code}
<%= numberFormat.format(properties.get("releaseMonth", long.class)) %>
{code}

It throws an exception:

{code}
Caused by: java.lang.IllegalArgumentException: Cannot format given
Object as a Number
at java.text.DecimalFormat.format(DecimalFormat.java:486)
at java.text.Format.format(Format.java:140)
at 
org.apache.jsp.apps.gtunes.album.html_jsp._jspService(html_jsp.java:171)
at 
org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspB
ase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at 
org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(Js
pServletWrapper.java:502)
... 68 more
{code}

If I use instead the primitive wrapper {{Long.class}}

{code}
<%= numberFormat.format(properties.get("releaseMonth", Long.class)) %>
{code}

everything works fine.

Looks like that

{code}
properties.get("", long.class)
{code}

gets {{NULL}} back

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira