Yeah that helps a ton. That's by far the best explanation of how to
use AutoBeans that I have seen, I recommend that this get added to the
current docs on the web.
That being said I'm still getting an error in one place. In this call
in my code AutoBeanCodex.encode(payloadAutoBean)...several levels down
in the call stack it makes this call:
AutoBeanUtils.getAutoBean(value) which returns null, and this result
is the input for the second parameter in the next method.
public static void doEncode(EncodeState state, AutoBean<?> bean) {
PropertyGetter e = new PropertyGetter(state);
try {
bean.accept(e);
} catch (HaltException ex) {
throw ex.getCause();
}
}
Which causes a NPE at bean.accept(e);
The 'value' parameter passed into AutoBeanUtils.getAutoBean(value)
above is a class defined as:
public class GWTInitializationMessage implements IGWTInitializationMessage {
private IGWTSessionReference sessionReference;
private IUUIDReference messageId;
public GWTInitializationMessage() {
this(null, null);
}
public GWTInitializationMessage(IUUIDReference messageId,
IGWTSessionReference sessionReference) {
this.sessionReference = sessionReference;
this.messageId = messageId;
}
public void setSessionReference(IGWTSessionReference sessionReference) {
this.sessionReference = sessionReference;
}
public IGWTSessionReference getSessionReference() {
return this.sessionReference;
}
public IUUIDReference getMessageId() {
return this.messageId;
}
public void setMessageId(IUUIDReference id) {
this.messageId = id;
}
}
public interface IUUIDReference extends Serializable {
String getUUIDAsString();
}
public interface IGWTSessionReference extends IsSerializable {
String getSessionId();
}
Which seems like it should be straightforward to handle...any ideas
why AutoBeans would fail to handle this?
Thanks,
-Dave
On Fri, Oct 19, 2012 at 2:59 PM, Jens <[email protected]> wrote:
> AutoBeanUtils.getAutoBean(payload); will only return an AutoBean<IPayload>
> instance if the method parameter already belongs to an AutoBean (see
> JavaDoc).
>
> So things would look like the following (from memory, hopefully its
> correct):
>
> //GWT client side
> MyAutoBeanFactory factory = GWT.create(MyAutoBeanFactory.class);
>
> //JVM = server side
> MyAutoBeanFactory factory =
> AutoBeanFactorySource.create(MyAutoBeanFactory.class);
>
> // now following code is the same on GWT client side and JVM/server side
>
> // creates a new empty AutoBean
> AutoBean<IPayload> payloadAutoBean = factory.getPayload();
>
> // creates a new AutoBean that contains the same data as the provided
> parameter
> AutoBean<IPayload> payloadAutoBean =
> factory.getPayload(yourPayloadPojoThatImplementsIPayload);
>
>
>
> // Optional: Modify / get data from your bean
> IPayload payload = payloadAutoBean.as();
> payload.setData(...);
>
>
> // serialize
>
> // If you still have access to payloadAutoBean then use it
> String json = AutoBeanCodex.encode(payloadAutoBean).getPayload();
>
> // If you dont have access to payloadAutoBean but only to IPayload (maybe
> you are in a different method)
> // and you know 'payload' comes from an AutoBean
> AutoBean<IPayload> bean = AutoBeanUtils.getAutoBean(payload);
> String json = AutoBeanCodex.encode(bean).getPayload();
>
>
> // deserialize
> AutoBean<IPayload> deserializedAutoBean = AutoBeanCodex.decode(factory,
> IPayload.class, json);
> IPayload deserializedPayload = deserializedAutoBean.as();
>
>
> I hope that helps.
>
> -- J.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/9Q1MicpiDeYJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.