AEM 6.1 - ValueMapDecorator doesn't wrap input map | Community
Skip to main content
dmytro_radchenk
New Participant
October 16, 2015
Solved

AEM 6.1 - ValueMapDecorator doesn't wrap input map

  • October 16, 2015
  • 4 replies
  • 1951 views

Hi,

We are using AEM 6 at the moment, and take advantage of ValueMap's in Sightly. We use the following code:

import org.apache.sling.api.resource.ValueMap;import org.apache.sling.api.wrappers.ValueMapDecorator;
ValueMap map = new ValueMapDecorator(new HashMap<String, Object>() {{ put("key", "value"); }});

map.size() is expected to be equal to 1, but with AEM 6.1, the values aren't wrapped anymore and the size of ValueMapDecorator is equal to 0.

In the attach there is map var expansion.

Thanks

 

P.S. using 

com.adobe.cq.commerce.common.ValueMapDecorator;

didn't solve the problem, but in AEM 6 both approaches worked fine

P.S.1 this classes are referenced from this dependency:

<dependency>    <groupId>com.adobe.aem</groupId><artifactId>uber-jar</artifactId><version>6.1.0</version><scope>provided</scope></dependency>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sham_HC

Sounds like a bug to me. Please file support request to investigate further.

4 replies

Sham_HC
Sham_HCAccepted solution
New Participant
October 16, 2015

Sounds like a bug to me. Please file support request to investigate further.

Tim_Donovanuk
New Participant
October 16, 2015

Hi Dmytro,

Using AEM Fiddle (available here) I have put together the following test, based on your code:

<%@page session="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="java.util.*, org.apache.sling.api.resource.ValueMap, org.apache.sling.api.wrappers.ValueMapDecorator" %> <% ValueMap map = new ValueMapDecorator(new HashMap<String, Object>() {{ put("key", "value"); }}); out.println(map.size()); %>

This outputs '1' and not '0' on my AEM 6.1 installation (clean install), so I cannot reproduce your issue at this time. Could you please try this same thing on your environment via AEM Fiddle? 

Thanks.

New Participant
October 16, 2015

Hi Tim,

We're facing the same issue as Dmytro mentioned above. I think AEM Fiddle proves that AEM 6.1 runtime environment provides a valid implementation of ValueMapDecorator - that's awesome, but doesn't help for unit tests running outside CQ. 

As if you put your test into JUnit test class and run it on your local machine in Maven or in an IDE - the unit test will fail. The reason of this is uber-jar provides just an empty wrapper for ValueMapDecorator along with other empty wrapper classes in org.apache.sling.api.*, com.day.cq.* and com.google.common.* packages.

So I'm wondering whether we're using the wrong dependency for AEM 6.1 API (https://repo.adobe.com/nexus/content/repositories/releases/com/adobe/aem/uber-jar/6.1.0/)?

As AEM 6.0 API contains not just wrappers but valid implementations for Sling API.

 

Thank you,

Anton

Tim_Donovanuk
New Participant
October 16, 2015

Hey Anton,

The code in the Uber jar is intentionally obfuscated. A request for unobfuscated classes can be raised via a support request and will be reviewed on a case-by-case basis.

Thanks,

Tim