Understanding @ExtraTypes

166 views
Skip to first unread message

opn

unread,
Sep 18, 2011, 5:24:14 PM9/18/11
to google-we...@googlegroups.com
I want to check out the new polymorphism features available for RequestFactory soon and stumbled upon the @ExtraTypes annotation. From the JavaDoc and this test I maybe should understand what exactly it does, but I don't! ;)

What is the effect when putting it on top of a proxy interface?
When do I put it above the RequestContext inteface?

Regards
Alex

Thomas Broyer

unread,
Sep 18, 2011, 7:19:40 PM9/18/11
to google-we...@googlegroups.com
Suppose you have a FooProxy, and a subinterface SubFooProxy (extends FooProxy), respectively mapped (@ProxyFor) to, say, Foo and SubFoo (extends Foo) domain objects.
You have a method with a return type of Foo/FooProxy but which could return a SubFoo/SubFooProxy. If SubFooProxy is never, ever, referenced directly in any method on a RequestContext or another proxy, then RF won't even know about its existence, so your returned SubFoo will always map to a FooProxy.
@ExtraTypes allows you to reference types that wouldn't be referenced otherwise. Putting @ExtraTypes(SubFooProxy.class) anywhere (really, it absolutely doesn't matter where you put the annotation) will tell RF about SubFooProxy, so a returned SubFoo will be mapped to a SubFooProxy.

opn

unread,
Sep 21, 2011, 6:27:24 AM9/21/11
to google-we...@googlegroups.com
Thomas, thanks again for your excellent answer!
Much clearer now!
Reply all
Reply to author
Forward
0 new messages