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

Christophe Jelger commented on SLING-6416:
------------------------------------------

Hi Stefan,

I simply wanted to test some code that reads a BigDecimal JCR value, something 
like {{valueMap.get("valueName", BigDecimal.class)}}

The value is originally stored as a {{Decimal}} in the JCR, and was exported 
for the mock-testing by default as a {{String}} with the usual 
/path/to/content/content.json JSON export. I also tried to manually modify the 
exported JSON file to replace the {{String}} with a {{Number}} to see if this 
fixes the problem, but it does not work in both cases.

It would be nice if the implementation could support both reading a JSON 
{{String}} or {{Number}} decimal representation, I mean both {{"123.45"}} and 
{{123.45}}.

I guess that something like the following code might be enough:

{code}
if (type == BigDecimal.class) {
  Object value = get(name);
  if (value instanceof String) {
    return (T) new BigDecimal((String) value);
  }
  else if (value instanceof Number) {
    return (T) new BigDecimal(value.toString());
  }
}
{code}

Actually the conversion in {{JcrPropertyMapCacheEntry}} is done with some handy 
helpers like {{NumberConverter}} or {{StringConverter}} which you might be able 
to also use here.

Thanks in advance
Christophe

> MockValueMap does not permit to get a BigDecimal value
> ------------------------------------------------------
>
>                 Key: SLING-6416
>                 URL: https://issues.apache.org/jira/browse/SLING-6416
>             Project: Sling
>          Issue Type: Bug
>          Components: Testing
>    Affects Versions: Testing ResourceResolver Mock 1.1.14
>            Reporter: Christophe Jelger
>            Assignee: Stefan Seifert
>
> The {{get(String name, Class<T> type)}} method in {{MockValueMap.java}} does 
> not support {{BigDecimal}} as a type. This is supported by the 
> {{JcrValueMap}} and {{JcrPropertyMapCacheEntry}} classes, and hence means 
> that it's not possible to test code that reads a {{BigDecimal}} property 
> value from the JCR.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to