开发者

Objectify - Add @Id to any class

开发者 https://www.devze.com 2023-03-02 04:27 出处:网络
I have many custom object classes used by both a server (GAE) and client (Android) in a RESTful system. For ease of maintainability, the code 开发者_JS百科for these objects is common between server an

I have many custom object classes used by both a server (GAE) and client (Android) in a RESTful system. For ease of maintainability, the code 开发者_JS百科for these objects is common between server and client.

In order to make these objects storable with Objectify on the server side, one field must be annotated @Id. However, I can't do this in each object class without importing javax.persistence on the client (or creating separate client/server copies of the code) (or, for every object, creating a "StorableX extends X" with cloning).

Is it possible to use an adapter or wrapper pattern to dynamically make any object storable via Objectify? What is the best practice for this?

Thanks, --John


There is normally no problem using an annotated class without the annotation interface being present in the classpath, even if the annotation is a runtime one. Of course, if the class byte-code is instrumented or if some class tries using the annotation at runtime, it's another matter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号