Skip to Content
author's profile photo Former Member
Former Member

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

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,

Add a comment
10|10000 characters needed characters exceeded

  • Former Member

    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.

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2016 at 10:44 AM

    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;
     }
    

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.