on 2022 May 06 2:22 PM
Hi guys!
When I try to map an object which contains Hybris Enum I get warnings in console. Those three attributes: '_TYPECODE', 'SIMLE_CLASSNAME' and 'code' are Hybris Enums specific properties.
Is there any special way how Hybris Enum mapping should be performed or is there a way how to exclude enum properties for Orika mapper globally?
[EL Warning]: 2022-05-06 16:11:26.366--Ignoring attribute [_TYPECODE] on class [hybris.core.enums.MobilityRatePlanType] as no Property was generated for it.
[EL Warning]: 2022-05-06 16:11:26.39--Ignoring attribute [SIMPLE_CLASSNAME] on class [hybris.core.enums.MobilityRatePlanType] as no Property was generated for it.
[EL Warning]: 2022-05-06 16:11:26.39--Ignoring attribute [code] on class [hybris.core.enums.MobilityRatePlanType] as no Property was generated for it.
...
Request clarification before answering.
In OOTB, each enum has a Orika converter. I will share the implementation for OrderStatus enum in commercewebservices extension.
In the file bin/modules/commerce-services/commercewebservices/web/webroot/WEB-INF/config/v2/dto-mappings-v2-spring.xml there is the following definition.
<bean class="de.hybris.platform.commercewebservices.core.mapping.converters.OrderStatusConverter"/>
And the Java class is implemented as follows
/*
* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/
package de.hybris.platform.commercewebservices.core.mapping.converters;
import de.hybris.platform.core.enums.OrderStatus;
import de.hybris.platform.webservicescommons.mapping.WsDTOMapping;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
/**
* Bidirectional converter between {@link OrderStatus} and String
*/
@WsDTOMapping
public class OrderStatusConverter extends BidirectionalConverter<OrderStatus, String>
{
@Override
public OrderStatus convertFrom(final String source, final Type<OrderStatus> destinationType,
final MappingContext mappingContext)
{
return OrderStatus.valueOf(source);
}
@Override
public String convertTo(final OrderStatus source, final Type<String> destinationType, final MappingContext mappingContext)
{
return source.toString();
}
}
In the commercewebservicescommons-beans.xml, OrderWsDTO have property named status defined as String instead of OrderStatus enum.<bean class="de.hybris.platform.commercewebservicescommons.dto.order.OrderWsDTO"
extends="de.hybris.platform.commercewebservicescommons.dto.order.AbstractOrderWsDTO">
<description>Representation of an Order</description>
<hints>
<hint name="wsRelated"/>
<hint name="alias">Order</hint>
</hints>
<property name="created" type="java.util.Date">
<description>Date of order creation</description>
</property>
<property name="status" type="String">
<description>Status of order</description>
</property>
... <!-- Other properties -->
</bean>
This is how mapping is done from HybrisEnumValue to String in WsDTO classes in OOTB. I am not aware of excluding some properties with Orika settings or configurations.Hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.