Yes, this is exactly the case. As long as type arguments generic
information is preserved we don't need any of Type getFromType() on
adapters itself, or as arguments for JsonbConfig.withAdapter method. I
tried to put this info in JsonbAdapter type javadoc. It simplyfies
adapter declaration. The only tricky part to watch out is with
TypeVariable adapters like MyAdapter<A, B>. I don't think it would be
that common, but we could throw specific expection on user, describing
that generic information is lost and we can't infere a type.
Roman
On 02/01/2016 03:00 PM, Romain Manni-Bucau wrote:
> So it means if you have a MyAdapter<A, B> (with generics still
> generics) then we assume we can't use withAdapter(new
> MyAdapter<String, Boolean>()) but withAdapters(new MyAdapter<String,
> Boolean>() {})? Asking in term of framework where you often get rid of
> the generics so wonder if it would work but we can start like it is
> and see the feedback we have for a potential 1.1.
>
> For the method naming just fixing the javadoc is fine I think but
> renaming the method marshall and unmarshall can be more explicit as
> well. No string opinion on that while it is somewhere.
>
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
> 2016-02-01 14:47 GMT+01:00 Roman Grigoriadi
> <roman.grigoriadi_at_oracle.com <mailto:roman.grigoriadi_at_oracle.com>>:
>
> Hi,
>
> I don't think we need it. I use anonymous adapers as follows:
>
> jsonb = JsonbBuilder.create(new JsonbConfig().withAdapters(new JsonbAdapter<Box, Crate>() {
> @Override public CrateadaptFrom(Box box) {
> ...}
>
> @Override public BoxadaptTo(Crate crate) {
> ...}
> }));
>
> A compile time generic information of type arguments From and To
> would is still available in case of anonymous class. You are right
> it isnt clear from javadoc which type of From and To stands for
> which object. "From" is for type that we would like to adapt. "To"
> is for type into which adaptation is done. But it is a "two way"
> process, which is always dependant on context - marshalling /
> unmarshalling. During marshalling we convert From to To and than
> serialize To. During unmarshalling we first deserialize into To,
> cibvert To to From which is set thereafter in resultin business
> model. Would it be any more clear if we rename methods "adaptFrom"
> and "adaptTo" to "adaptMarshalling" and "adaptUnmarshalling"?
> Regards, Roman
> On 01/29/2016 07:10 PM, Romain Manni-Bucau wrote:
>> do we add a withAdapter(from, to, adapter) method to JsonbConfig?
>> it would allow anonymous adapters to work instead of having to
>> create a class.
>> Also the javadoc should be updated since to and from method have
>> the same and we don't know if the json type should be from or to
>> - I'd assume from but would be good to make it clear. Or do we
>> support auto detection (ie <A, B> = <B, A> for the runtime? this
>> would prevent custom logic in one particular way if so)
>> Romain Manni-Bucau
>> @rmannibucau
>> http://www.tomitribe.com
>> http://rmannibucau.wordpress.com
>> https://github.com/rmannibucau
>
>