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

产品(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;


看起来无论发生什么过程都在这里递归进行。您必须打破递归性。

但是,经过一些搜索之后,由于您使用的has support for recursivity API看起来很奇怪-链接中的情况仅针对实例,而不是实例的集合。

尝试更新的版本?

编辑有一个@PodamCollection批注,也许它可以帮助您

10-01 07:52