简体   繁体   中英

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. everything works fine, i receive a valid json string on the client and can decode that json string to the AutoBean back again. only the autobean.as() does not return anything different than the autobean itself.

IContactDto and ContactDto just contain getters and setters. and this is the facbory i wrote

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

// 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.

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.

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM