2

请告诉我如何正确使用 PodamFactory 进行填充。我在调用时得到StackOverflowErrorproductList源类列表)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)
4

3 回答 3

1

问题很可能在这里:

private List<Product> productList;

看起来无论发生什么过程都会在这里递归。你必须打破这种递归性。

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

试试更新的版本?

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

于 2013-06-17T10:18:59.273 回答
1

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

于 2020-10-28T12:27:18.463 回答
0

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

于 2014-01-22T19:00:49.970 回答