cancel
Showing results for 
Search instead for 
Did you mean: 

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found

sharada1234
Explorer
0 Kudos

Hi Team,

Currently we are upgrading our SAP commerece hybris from 6.1 to 2105.We are managing our storefront with AEM and using hybris to manage products,cart and orders.As part of this we developed REST API's to fetch products from hybris.

This is how our Rest API url looks like to fetch a product:

https://localhost:1905/trwebservices/v1/testcountry/products/1234

While upgrading to 1905,the above URL giving 500 server error,throwing a error in backend.tried many solutions but none of the solutions is working.below is the stacktrace

"SEVERE: Servlet.service() for servlet [springmvc] in context with path [/trwebservices] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.thomsonreuters.ecom.facades.product.data.TRPriceDataTypeUtil]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.thomsonreuters.ecom.facades.product.data.TRPriceDataTypeUtil and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.thomsonreuters.ecom.facades.product.data.TRProductData["price"]->com.thomsonreuters.ecom.facades.product.data.TRPriceData["util"])] with root cause

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.thomsonreuters.ecom.facades.product.data.TRPriceDataTypeUtil and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.thomsonreuters.ecom.facades.product.data.TRProductData["price"]->com.thomsonreuters.ecom.facades.product.data.TRPriceData["util"])

at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)"

Tried Solutions:

1.Added getters and setters in TRPriceDataTypeUtil class.and made access specifiers public.still same error.

2.Added @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) in TRPriceDataTypeUtil.Still same issue.

3.Created Objectmapper class and added this:

ObjectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);.Still same issue.

4.Added latest jackson jars and changed imports,this time it was not showing the error but in frontend it is giving 500

4.Removed the complete class TRPriceDataTypeUtil but still showing same issue.

Please suggest?

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

I get almost the same error when doing an expand with filter CqnSelect

ERR Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.sap.cds.impl.parser.token.RefSegmentImpl$FilteredSegmentImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.Collections$SingletonList[0])

for this type of expand

Select.from(ASSORTMENT) .columns( Assortment_::_all, a -> a.toCompBP() .filter(bp -> bp.anyMatch(ofBusinessPartnerFinal)) .expand(AssortmentBusinessPartner_::_all), a -> a.toCompProduct() .filter(p -> p.anyMatch(ofProductFinal)) .expand(AssortmentProduct_::_all) ) .where(fullPredicate);

I tried with custom objectMapper Bean with disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) and the error is still alive

safin
Advisor
Advisor
0 Kudos

Hi Sharada,

The log shows Jackson is trying to serialize a bean with no attributes nor methods

You have different ways to fix it:

=== method1: avoid using any empty object ===

Iterate over your code to avoid empty object, something like this: "new Object()", if yes, replace it with "null"

=== method 2: avoid failure on empty object ===

ObjectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); (for jackson < 2.*)

or

ObjectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

Normally, method 1 is better since it doesn't change Jackson default behavior during fixing the problem.

Hopefully, it can help you a little.

sharada1234
Explorer
0 Kudos

Hi Gang Li,

Thank you for your reply. I have tried above solution already. When I applied above solution it is not throwing error in backend but issue remains same on frontend. Still throwing 500 internal server error.

Is there anything that I am missing here?

safin
Advisor
Advisor
0 Kudos

Would you please paste the detailed log?

sharada1234
Explorer
0 Kudos

Please find detailed log . stacktrace.txt

safin
Advisor
Advisor
0 Kudos

Would you please also paste the related code including TRProductData, TRPriceData and TRPriceDataTypeUtil?