如何“toString()”用于日志记录和调试的 GWT EntityProxy 衍生产品?
GWT 2.1.1 有非常好的框架 - RequestFactory 以及所有 EntityProxy 和其他东西。
我正在寻找一种方法来序列化实现 EntityProxy 的运行时实例以进行调试和日志记录等。我不关心格式,只要它是人类可读的即可。 更具体地说,我想要类似 Apache Commons Lang 提供的东西 ReflectionToStringBuilder 可能有某种方法可以使用 GWT 内部的 JSON 序列化机制?如果是,如何使其更具可读性?
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
String stringRep = ReflectionToStringBuilder.toString(this);
GWT 2.1.1 has very good framework - RequestFactory with all the EntityProxy and stuff.
I am looking for a way to serialize runtime instances that implement EntityProxy for debugging and logging etc. I do not care for format as long as it human readable.
To be more specific I would like to have something like the provided by Apache Commons Lang
ReflectionToStringBuilder
May be there is some way to use the JSON serialization mechanics that GWT has inside? if yes how to make it a bit more readable?
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
String stringRep = ReflectionToStringBuilder.toString(this);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
至少有两种解决方案:
第一:基于 Thomas Broyer 的想法,
产生如下内容:
第二:基于 AutoBean 框架,
它生成类似的字符串
第二个是正是我所需要的 - 它在日志中更具可读性。
There are at least 2 solutions:
First: Based on the idea by Thomas Broyer
Which produce something like this:
Second: Based on the AutoBean framework
Which produce string like
The second is just what I need - it more readable in log.
我还没有尝试过,但看看 RequestFactory#getSerializer,javadoc 中有一些示例代码 ProxySerializer。
I haven't tried it but have a look at RequestFactory#getSerializer, there's some sample code in the javadoc for the ProxySerializer.
如果使用该方法
toJson(EntityProxy entityProxy)
将其更改为
toJson(BaseProxy proxy),
然后您可以记录 Value 和 Entity Proxy 对象。
If using the method
toJson(EntityProxy entityProxy)
change this to
toJson(BaseProxy proxy)
and then you can log Value and Entity Proxy objects.