cancel
Showing results for 
Search instead for 
Did you mean: 

How to change response structure of OCC V2 services for "products/search?fields=FULL" service?

Former Member
0 Kudos

Hi,

I am working on hybris 5.7.0.3 OCC V2 Services. I am using "products/search?fields=FULL" service to get list of products. In response I am getting two images tags separately for thumbnail & product format of a single product.

 <product>
   <images>
     <format>thumbnail</format>
     <imageType>PRIMARY</imageType>
   </images>
   <images>
     <format>product</format>
      <imageType>PRIMARY</imageType>
   </images>
 </product>

Now I want single Images tags under which two image tags will be displayed for thumbnail & product format (As mentioned below).

 <product>
   <images>
      <image>
          <format>thumbnail</format>
          <imageType>PRIMARY</imageType>
       </image>
      <image>
           <format>product</format>
           <imageType>PRIMARY</imageType>
      </image>
   </images>
 </product>

How to achieve this?

This is working fine for "/products/productCode?fields=FULL"

Thanks & Regards,

Former Member
0 Kudos

The service mentioned above "../products/search?fields=FULL" is OOB provided by hybris.

For product detail of single product I am getting proper response structure as mentioned below Service URL: "/products/productCode?fields=FULL" Response: thumbnail PRIMARY product PRIMARY

I have changed the value of property "wrapCollections" to True

So I want similar response structure for product listing service.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

There is a bug in MoxyJaxbContextFactoryImpl class which prevents wrapping of collections for more than one level type hierarchy. It doesn't matter if you set wrapDepth to 2 or 100 it will work as set to 1. To fix this you need to change implementation of MoxyJaxbContextFactoryImpl.getInnerFields method. Possible solution would look like:

protected static Set getInnerFields(final Class clazz, final int depth) { final Set result = new HashSet(); if (depth <= 0) { return result; }

     final Set<Class> visitedClesses = new HashSet<Class>();
     final Queue<Tuple2<Class, Integer>> workQueue = new LinkedList<MoxyJaxbContextFactoryImpl.Tuple2<Class, Integer>>();

     workQueue.add(new Tuple2<Class, Integer>(clazz, Integer.valueOf(0)));

     while (!workQueue.isEmpty())
     {
         final Tuple2<Class, Integer> item = workQueue.poll();
         final Class itemClass = item.getFirst();
         //work on one class only once
         if (visitedClesses.contains(itemClass))
         {
             continue;
         }

         final int itemDepth = item.getSecond().intValue();
         final Field[] fields = itemClass.getDeclaredFields();

         for (final Field field : fields)
         {
             final Class fieldClass = field.getType();
             if (baseExcludeClasses.contains(fieldClass))
             {
                 continue;
             }
             Class nextType = null;
             if (Collection.class.isAssignableFrom(fieldClass))
             {
                 final ParameterizedType pt = (ParameterizedType) field.getGenericType();
                 final Type[] typesInside = pt.getActualTypeArguments();
                 if (typesInside.length == 1 && typesInside[0] instanceof Class)
                 {
                     nextType = (Class) typesInside[0];
                     result.add(nextType);
                 }
             }
             else
             {
                 nextType = fieldClass;
             }

             if (itemDepth < depth && nextType != null)
             {
                 workQueue.add(new Tuple2<Class, Integer>(nextType, Integer.valueOf(itemDepth + 1)));
             }
         }

         visitedClesses.add(itemClass);
     }

     return result;
 }

Former Member
0 Kudos

Thanks Robert for your reply. I will try this solution.

Thanks & Regards,

0 Kudos

Hi ,

This solution is not working for Cart service.

      <code>00001006</code>
      <entries>

....

... .

Do you have any idea on this?