Jemos PODAM StackOverflowError



请告诉我如何正确使用PodamFactory填充。当调用podamFactory.manufacturePojo(Product)时,我得到productListStackOverflowError(源类列表)。

产品(A)来源:

public class Product {
    private String productName;
    private String productDescription;
    private Double price;
    private Boolean availability;
    private List<Product> productList;
    // getters & setters
}
异常:

Caused by: java.lang.StackOverflowError
    sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(SignatureParser.java:253)
    sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(SignatureParser.java:270)
    sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:244)
    sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:228)
    sun.reflect.generics.parser.SignatureParser.parseTypeArgument(SignatureParser.java:319)
    sun.reflect.generics.parser.SignatureParser.parseTypeArguments(SignatureParser.java:284)
    sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(SignatureParser.java:260)
    sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(SignatureParser.java:270)
    sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:244)
    sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:228)
    sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java:359)
    sun.reflect.generics.parser.SignatureParser.parseZeroOrMoreTypeSignatures(SignatureParser.java:469)
    sun.reflect.generics.parser.SignatureParser.parseFormalParameters(SignatureParser.java:446)
    sun.reflect.generics.parser.SignatureParser.parseMethodTypeSignature(SignatureParser.java:436)
    sun.reflect.generics.parser.SignatureParser.parseMethodSig(SignatureParser.java:141)
    sun.reflect.generics.repository.ConstructorRepository.parse(ConstructorRepository.java:37)
    sun.reflect.generics.repository.ConstructorRepository.parse(ConstructorRepository.java:25)
    sun.reflect.generics.repository.AbstractRepository.<init>(AbstractRepository.java:56)
    sun.reflect.generics.repository.GenericDeclRepository.<init>(GenericDeclRepository.java:30)
    sun.reflect.generics.repository.ConstructorRepository.<init>(ConstructorRepository.java:33)
    sun.reflect.generics.repository.MethodRepository.<init>(MethodRepository.java:28)
    sun.reflect.generics.repository.MethodRepository.make(MethodRepository.java:41)
    java.lang.reflect.Method.getGenericInfo(Method.java:94)
    java.lang.reflect.Method.getGenericParameterTypes(Method.java:282)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojoInternal(PodamFactoryImpl.java:1464)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojo(PodamFactoryImpl.java:109)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1681)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1568)
    uk.co.jemos.podam.api.PodamFactoryImpl.fillCollection(PodamFactoryImpl.java:2078)
    uk.co.jemos.podam.api.PodamFactoryImpl.resolveCollectionValueWhenCollectionIsPojoAttribute(PodamFactoryImpl.java:1973)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1646)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojoInternal(PodamFactoryImpl.java:1485)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojo(PodamFactoryImpl.java:109)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1681)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1568)
    uk.co.jemos.podam.api.PodamFactoryImpl.fillCollection(PodamFactoryImpl.java:2078)
    uk.co.jemos.podam.api.PodamFactoryImpl.resolveCollectionValueWhenCollectionIsPojoAttribute(PodamFactoryImpl.java:1973)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1646)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojoInternal(PodamFactoryImpl.java:1485)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojo(PodamFactoryImpl.java:109)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1681)
    uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1568)
    uk.co.jemos.podam.api.PodamFactoryImpl.fillCollection(PodamFactoryImpl.java:2078)

问题很可能就在这里:

private List<Product> productList;

看起来这里发生的任何过程都是递归的。你必须打破这种递归性

然而,经过一番谷歌搜索后,它看起来很奇怪,因为您使用的API支持递归——但是链接中的案例是针对实例的,而不是实例的集合。

尝试更新的版本?

EDIT有一个@PodamCollection注释,也许它可以帮助你

从3.1.3版本开始,PODAM通过检测POJO依赖项中的循环并减少递归来优雅地处理这种情况。

Try podamFactory.manufacturePojo(ArrayList.class, Product.class)

相关内容

  • 没有找到相关文章

最新更新