Page 1 of 1

Infinite recursion

Posted: Thu Mar 16, 2017 3:10 pm
by rajaman
Hi, I have just started using broadleaf. I tried to write an Api call to fetch data from SkuBundleItemImpl table and got infinite recursion error . I looked into the SkuBundleItemImpl entity and found that it had @ManyToOne relationship with ProductBundleImpl which had @OneToMany relationship with SkuBundleItemImpl.

I know one of the solution is to use @JsonIgnore annotation in entity but entity code is in framework. So it's simply not possible to go and add this annotation. Could you guys give me a better approach to tackle this issue.

Re: Infinite recursion

Posted: Tue Jul 25, 2017 3:23 pm
by phillipuniverse
You can actually add things like @JsonIgnore and any other Jackson annotations that you want by using Jackson Mixins (#8 on that page). if you are creating your own ObjectMapper to do the serialization you can just do it there. If you are using the Broadleaf APIs you can customize the ObjectMapper like this:

Code: Select all

public class RestApiMvcConfiguration extends BroadleafRestApiMvcConfiguration {

        protected Jackson2ObjectMapperBuilder getObjectMapperBuilder() {
            return super.getObjectMapperBuilder()
                .mixin(SkuBundleItemImpl.class, MyMixin.class);

The Broadleaf forums are being retired as a readonly archive of questions. For active discussions and questions, check out the broadleaf-commerce tag on Stack Overflow which is actively monitored by the Broadleaf team.