好吧,我已经达到了世纪的头脑,坐了几个小时思考这个。我将在这里快速添加一个示例:
public class AdUnitSizes {
protected String environmentType;
@XmlElement(name = "size")
protected List<Size> sizes;
protected List<Companions> companions;
现在基本上,如果我将其构建为 XML 文件,它会假设表示类似这样的内容(注意,Companions 的类型为 AdUnitSize[])
<adUnitSizes>
<size>
<width>800</width>
<height>600</height>
<isAspectRatio>true</isAspectRatio>
</size>
<environmentType>BROWSER</environmentType>
<companions> <!--adunitsize[]-->
<size>
<width>800</width>
<height>600</height>
<isAspectRatio>true</isAspectRatio>
</size>
<environmentType>BROWSER</environmentType>
<companions>
<size>
<width>800</width>
<height>600</height>
<isAspectRatio>true</isAspectRatio>
</size>
<environmentType>BROWSER</environmentType>
<companions>...</companions>
</companions>
</companions>
</adUnitSizes>
现在,正如我试图指出的,AdUnitSizes 包含 3 个字段。尺寸、EnvironmentTypes 和 Companions。我现在尝试在 java 中做的事情,使用我创建的对象包装器(第一个示例)是遍历每个子 Companions 对象,以及他们的子 Companions 对象,直到迭代无法继续(在我们的系统中不太可能) Companions 的深度会超过 3 个级别,但无论如何我都需要满足这一点)
这是我尝试过的:
AdUnitSize[] adUnitSizeArray = adUnit.getAdUnitSizes();
if(adUnitSizeArray != null){
List<AdUnitSizes> adUnitSizesList = adUnitWrapper.getAdUnitSizes();
for(int i = 0; i < adUnitSizeArray.length; i++){
AdUnitSizes adUnitSizes = new AdUnitSizes();
aem.adservices.google.dfp6.om.Size size = new aem.adservices.google.dfp6.om.Size(); //Name clash with Google Size Class
size.setHeight(adUnitSizeArray[i].getSize().getHeight());
size.setWidth(adUnitSizeArray[i].getSize().getWidth());
size.setIsAspectRatio(adUnitSizeArray[i].getSize().getIsAspectRatio());
adUnitSizes.getSizes().add(size);
adUnitSizes.setEnvironmentType(adUnitSizeArray[i].getEnvironmentType().getValue());
List<Companions> companionsList = adUnitSizes.getCompanions();
//Need to iterate through all of adUnitSizeArray's Companions, and its companions children and so forth
}
}
有任何想法吗?我接近这个错误吗?