How is the "toString ()" Derived EntityProxy GWT for Logging and Debugging?

GWT 2.1.1 has a very good structure - RequestFactory with all EntityProxy, etc.

I am looking for a way to serialize runtime instances that implement EntityProxy for debugging and logging, etc. I do not need a format if it is human readable. To be more specific, I would like to have something like the one provided by Apache Commons Lang ReflectionToStringBuilder Maybe there is some way to use the JSON serialization mechanics that is inside GWT? if so, how to make it more readable?

import org.apache.commons.lang.builder.ReflectionToStringBuilder; String stringRep = ReflectionToStringBuilder.toString(this); 
+4
source share
3 answers

There are at least two solutions:

First: based on the idea of Thomas Broyer

 public static String toString(EntityProxy entityProxy) { DefaultProxyStore store = new DefaultProxyStore(); Swap.requestFactory.getSerializer(store).serialize(entityProxy); return store.encode(); } 

Something like that:

 {"V":"211","P":{" 1@2 @biz.daich.swap.shared.dto.UserAccountProxy":{"O":"PERSIST","R":"2","Y":1,"T":"biz.daich.swap.shared.dto.UserAccountProxy","P":{"id":null,"items":null,"channelId":null,"lastActive":1296194777916,"name":null,"emailAddress":" test@example.com ","lastReported":1296194777916,"lastLoginOn":1296194777916}}}} 

Second: based on AutoBean framework

 public static String toJson(EntityProxy entityProxy) { return AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(entityProxy)).getPayload(); } 

Which produce a string like

 {"emailAddress":" test@example.com ","lastActive":1296194777916,"lastLoginOn":1296194777916,"lastReported":1296194777916} 

The second one is what I need - it is more readable in the magazine.

+4
source

I have not tried it, but I'll look at RequestFactory # getSerializer , there is sample code in javadoc for ProxySerializer .

+2
source

If using the toJson method (EntityProxy entityProxy)

change it to

toJson (BaseProxy proxy)

and then you can register proxy and entity proxy objects.

0
source

Source: https://habr.com/ru/post/1337064/


All Articles