gpt4 book ai didi

java - GWT Autobean Bean 为空

转载 作者:行者123 更新时间:2023-12-01 08:54:32 32 4
gpt4 key购买 nike

请帮帮我,我做错了什么

InfraNameModel

public interface InfraNameModel {
String getInfraName();

void setInfraName(String infraName);
}

InfraNameModelImpl

public class InfraNameModelImpl implements InfraNameModel {
private String infraName;

@Override
public String getInfraName() {
return infraName;
}

@Override
public void setInfraName(String infraName) {
this.infraName = infraName;
}
}

InfraNameModelList

public interface InfraNameModelList<T extends InfraNameModel> {

public List<T> getInfraNameModelList();

public void setInfraNameModelList(List<T> infraNameModel);
}

InfraNameModelListImpl

public class InfraNameModelListImpl implements InfraNameModelList<InfraNameModel> {
private List<InfraNameModel> infraNameModelList;

@Override
public List<InfraNameModel> getInfraNameModelList() {
return infraNameModelList;
}

@Override
public void setInfraNameModelList(List<InfraNameModel> infraNameModelList) {
this.infraNameModelList = infraNameModelList;
}
}

IBeanFactory

public interface IBeanFactory extends AutoBeanFactory {
IBeanFactory INSTANCE = GWT.create(IBeanFactory.class);

AutoBean<InfraNameModel> infraNameModel();

AutoBean<InfraNameModelList> infraNameModelList();
}

...

            InfraNameModelList infraNameModelList = beanFactory.deserializeFromJson(" [{\"infraName\":\"TEST1\"},{\"infraName\":\"TEST2\"}}");
if (infraNameModelList == null)
logger.info("infraNameModelList=== null");
else
logger.info("infraNameModelList not null " + infraNameModelList);
List<InfraNameModelImpl> infraNameModel = infraNameModelList.getInfraNameModelList();
if (infraNameModel == null)
logger.info("infraNameModel=== null");
else
logger.info("infraNameModel=== not null " + infraNameModel);
InfraNameModelImpl infraNameModelImpl = infraNameModel.get(0);
if (infraNameModel == null)
logger.info("infraNameModelImpl=== null");
else
logger.info("infraNameModelImpl=== not null " + infraNameModelImpl);
logger.info("===" + infraNameModelImpl.getInfraName());

所以我有这样的错误在这一行

ConsoleLogger.java:32 infraNameModel=== null

为什么 infraNameModel 为空??? =(

===SUCCESS
ConsoleLogger.java:32 ===[{"infraName":"TEST1"},{"infraName":"TEST2"}]
ConsoleLogger.java:32 infraNameModelList not null by.client.models.infraNameModel.InfraNameModelListAutoBean$2@36
ConsoleLogger.java:32 infraNameModel=== null
ConsoleLogger.java:32 (TypeError) : Cannot read property 'get_18_g$' of null
H3f_g$ @ ConsoleLogger.java:32
eAf_g$ @ SimpleConsoleLogHandler.java:36
szf_g$ @ Logger.java:312
rzf_g$ @ Logger.java:302
Pzf_g$ @ Logger.java:236
rad_g$ @ LogConfiguration.java:169
lab_g$ @ Impl.java:186
$9_g$ @ Impl.java:293
(anonymous) @ Impl.java:77
ConsoleLogger.java:55 Exception: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'get_18_g$' of null
ConsoleLogger.java:32 TypeError: Cannot read property 'get_18_g$' of null
at uHg_g$.D$g_g$ [as onSuccess_8_g$] (Configuration.java:71)
at uHg_g$.xHg_g$ [as onSuccess_1_g$] (Configuration.java:55)
at S9f_g$.Ny_g$ [as onResponseReceived_0_g$] (AbstractRequestCallback.java:94)
at ZLc_g$.aMc_g$ [as fireOnResponseReceived_0_g$] (Request.java:250)
at hNc_g$.iNc_g$ [as onReadyStateChange_0_g$] (RequestBuilder.java:412)
at XMLHttpRequest.<anonymous> (XMLHttpRequest.java:329)
at X9_g$ (Impl.java:239)
at $9_g$ (Impl.java:291)
at XMLHttpRequest.<anonymous> (Impl.java:77)

最佳答案

Why infraNameModel is null??? =(

因为数组没有 infraNameModelList 属性。

您必须将 JSON 数组包装到具有此类属性的对象中,以使其与您的 AutoBean 模型匹配。

关于java - GWT Autobean Bean 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42136109/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com