问题标签 [autobean]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3588 浏览

gwt - 包含类型化成员的参数化 AutoBean 类型

问题

有没有办法使用 AutoBean 框架反序列化 JSON,以便生成的 bean 具有影响其一个或多个成员的类型的类型参数?

背景

带有 JSON 结果的 RPC

我正在使用 GWT ( RequestBuilder) 来执行 RPC 请求。返回的 JSON 有效负载具有以下形式:

对象的resultSet类型取决于我调用的特定 RPC。

AutoBean 接口

我想使用 AutoBean 反序列化这个 JSON。我试图表示这个对象如下:

我还创建了适当的接口来表示可能存在于resultSet. 最后,我设置了对AutoBeanCodex.decode.

运行代码

尝试在开发模式下运行此代码会导致控制台中出现以下堆栈跟踪:

基于此堆栈跟踪,我的预感如下:

  1. 类型擦除使它看起来RpcResults.getResultSet()返回一个 raw List
  2. AutoBean 反序列化器尝试ObjectresultSet.
  3. 失败

再次提问

我是否在 AutoBean API 中遗漏了一些可以让我轻松做到这一点的东西?如果没有,我应该研究一个明显的攻击点吗?对于我正在做的事情(除了我已经在使用的 JSONParser 和 JavaScriptObject 之外),是否有更明智的选择?

0 投票
1 回答
739 浏览

gwt - 列表> 在 AutoBeanFactory 中

我在 RequestFactory 之外使用 AutoBeanFactory 将对象转换为 JSON 和从 JSON 转换对象。它工作得非常好,但我刚刚添加了一种 Object 类型,它使用 NullPointerException 使 codex 崩溃,我不知道为什么。

我正在使用 GWT 2.2.0。

对象类:

工厂类:

当我打电话时AutoBeanCodex.encode(anInstanceOfAnImplementationOfPolicy),我得到一个 NullPointerException:

似乎 AutoBeanCodex 应该再次调用 visitCollectionProperty,所​​以也许这是一个值得 Google 解决的错误。另一方面,也许我做错了什么,或者这是明确不支持的。

我希望有人对此有一些经验,或者 BobV 有一个建议:)

0 投票
2 回答
6248 浏览

json - 带有 POJO 类而不是接口的 GWT AutoBean

我希望有人可以为我的问题提出一个简单的解决方案。

我有一个 POJO,说:

我想使用 GWT 的 AutoBean 功能将此 bean 序列化/反序列化为 JSON,但 AutoBean 需要一个接口:

我有一个 AutoBeanFactory 设置:

使用工厂和 Person 接口,我可以反序列化 JSON Person:

但是,如果我用 Person 类替换 Person 接口,我会收到一个 AutoBeanFactoryGenerator 异常,指出:“com.xxx.xxx.Person 不是接口”。

如何在我的简单 POJO 中使用 AutoBean 序列化/反序列化?

0 投票
2 回答
1598 浏览

gwt - GWT Autobeans / NoClassDefFoundError:我做错了什么?

我正在尝试使用AutobeansGWT中将POJO序列化为JSON 我不断收到一个和,两者都在寻找。这是在标记Place的上下文中。NoClassDefFoundErrorClassNotFoundExceptionorg.json.JSONObject

我创建了一个 JUnit 测试来隔离问题。测试是:

我的堆栈跟踪是

这是 Tokenizer 的相关位:

我已经在我的 .gwt.xml 中添加了 Autobeans,但我似乎仍然缺少一些东西。

0 投票
1 回答
1431 浏览

json - GWT Autobean JSON 规范

如果我在 GWT 客户端上使用 Autobean 序列化我的 POJO(通过 RequestBuilder 发送)但我打算使用 groovy、perl 或 php 来处理该请求,我需要知道 Autobean 的序列化格式。

Autobean 的 JSON 格式规范是什么以及在哪里可以获得?

0 投票
2 回答
1270 浏览

java - Is there a way to downcast a GWT AutoBean?

I've been using AutoBeans to map JSON data coming from a non GWT-RPC Java based web service. Everything has been working so far except for one mapping.

On the server side, the Class has a property of type Map where MyAbstractParentObject is the parent class of about 15 different child classes.

When I map that to a corresponding AutoBean interface on the client I'm not able to downcast MyAbstractParentObject to its child type after it's been decoded. I looked all over the GWT docs and 'the Googles' to see if AutoBeans even has polymorphic support but couldn't get an answer either way. Interceptors and Categories don't seem to be able handle this, just methods they want to exist in the interface that aren't getters/setters.

I was attempting to do a workaround using the type field in the JSON data to create an instance of the child class but the AutoBean does not give me access to the raw JSON, even though in the debugger I can see it as a protected field called 'data'. If I try to decode the original bean it will only have the fields in the MyAbstractParentObject.

The only alternatives I can see are to:

  1. Extend or create my own AutoBeanCodex that can properly handle the children of MyAbstractParentObject when it decodes the JSON.
  2. Find a way to get to the raw JSON in the MyAbstractParentObject AutoBean and use that to create and instance of the child class on the fly.
  3. Switch to some other JSON-GWT Serialization framework like GWTProJSONSerializer or piriti.

Any help would be appreciated.

0 投票
1 回答
382 浏览

gwt - Autobean 类别在开发模式下运行良好,但在 GWT 编译时失败

此代码在开发模式下运行良好,但在 gwt 编译时失败并出现异常。我不知道为什么。MechanicCategory 类在路径上,与 eclipse 一起编译良好,并且在开发模式下运行良好,但 gwt 编译失败...... :-/ 任何想法?

0 投票
0 回答
392 浏览

gwt - 如何覆盖日期的自动豆编码器和解码

我想做的是使用 ISO 8601 添加自定义编码器/解码器。我想我可以创建一个自定义版本的 GWT 构建,但这不方便......有什么想法吗?谢谢!

0 投票
2 回答
2585 浏览

java - 序列化为 GWT AutoBean 时如何保留 LinkedHashMap 的顺序?

我尝试过使用Map,HashMapLinkedHashMap作为 AutoBean 工厂的类型,并且总是在序列化之后改变初始元素的顺序。

我不想发送ArrayList包含订单数据的附加信息。有没有办法强制 AutoBean 保持秩序Map

0 投票
0 回答
494 浏览

java - GWT Autobeans 和日期

我正在尝试使用 AutoBeans,我正在将日期为“2011-12-08T10:07:24.247-05:00”的 json 解析为我的 bean 中的 Date 变量,但 StringQuoter.tryParseDate() 始终返回 null。另外,如果我有一个字符串“2011-12-08”,我可以不指定一个格式化程序来返回一个日期,例如 piriti 允许你使用 @Mapping(value = "date", format = "dd.MM. yyyy"),如此处所示http://code.google.com/p/piriti/wiki/ExternalMappings