[英]Autobean returns an autobean after using as()
in my gwt project i am sending objects with the gwt channel api to the client and use Autobean to encode and decode those objects. 在我的gwt项目中,我将使用gwt通道api将对象发送给客户端,并使用Autobean编码和解码这些对象。 everything works fine, i receive a valid json string on the client and can decode that json string to the AutoBean back again.
一切正常,我在客户端上收到一个有效的json字符串,并且可以将该json字符串再次解码回AutoBean。 only the autobean.as() does not return anything different than the autobean itself.
只有autobean.as()不会返回与autobean本身不同的任何东西。
IContactDto and ContactDto just contain getters and setters. IContactDto和ContactDto仅包含getter和setter。 and this is the facbory i wrote
这是我写的
AutoBeanFactory AutoBeanFactory
public interface DtoFactory extends AutoBeanFactory{
AutoBean<IContactDto> contactDto(IContactDto contactDto);
}
Server-side code 服务器端代码
DtoFactory dtoFactory = AutoBeanFactorySource.create(DtoFactory.class);
AutoBean<IContactDto> iContactDto = dtoFactory.contactDto(contactDto);
String sJson = AutoBeanCodex.encode(autoBean).getPayload();
// sending this json to the client
Client-side code 客户端代码
this is the code i use for decoding the valid json string 这是我用于解码有效json字符串的代码
// sJson string looks like {"id":"6473924464345088", "lastUpdate":"1475914369346", "fullName":"testName1","givenName":"testName2"}
DtoFactory factory = GWT.create(DtoFactory.class);
AutoBean<IContactDto> autoBean = AutoBeanCodex.decode(factory, IContactDto.class, sJson); // debugger: IContactDtoAutoBean_1_g$
IContactDto iDto = autoBean.as(); // debugger still shows IContactDtoAutoBean$1_1_g$
i can actually use the getters and setters of this object, but as soon as i try continue to work this those objects i get a problem with the type signature. 我实际上可以使用该对象的getter和setter方法,但是一旦我尝试继续使用这些对象,我就会遇到类型签名的问题。
any ideas how i can get the object i encoded back again? 任何想法,我怎样才能得到我再次编码的对象?
AutoBean#as()
returns a “proxy implementation of the T interface which will delegate to the underlying wrapped object, if any.” (source: javadoc ), it will never return the wrapped object itself. AutoBean#as()
返回“ T接口的代理实现,它将委托给基础包装的对象(如果有)。” (源: javadoc ),它将永远不会返回包装的对象本身。
Moreover, when deserializing from JSON, there's no wrapped object, a new autobean is created "from scratch" and then filled with JSON (it actually directly wraps a Splittable
from the parsed JSON: super-lightweight, just a thin typesafe wrapper around a JS object –or a org.json.JSONObject
when not in the browser.) 而且,当从JSON反序列化时,没有包装的对象,“从头开始”创建一个新的autobean,然后填充JSON(它实际上直接从解析的JSON中包装了一个
Splittable
:超轻量级,只是一个围绕JS的薄类型安全包装器对象-或不在浏览器中的org.json.JSONObject
。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.