You can create a class that wraps everything you might want to transport
and use that class in the interface instead.

One way is like this:

    public abstract class Property<T> implements Serializable {
        T value;
    }

    public class LongProperty extends Property<Long> {
    }

    public class DoubleProperty extends Property<Double> {
    }

    public interface Service {
        HashMap<String, Property<?>> getFoo();
    }

another way:

    public enum PropertyType { INTEGER, LONG, DOUBLE, ... }

    public class Property implements Serializable {
        PropertyType type;

        Long longValue;
        Date dateValue;
        Integer intValue;
    }

    public interface Service {
        HashMap<String, Property> getFoo();
    }

However you do it, do be aware that you may well increase the required
size of data sent over the network using techniques like this - and the
time taken to serialize/deserialize it.

@gwt.typeArgs was needed before GWT 1.5 when GWT first supported
generics. You don't need it now (I'm not sure if you still can use it)
and it wouldn't help here anyway because generics let you specify the
same information.


Paul

kriswpl wrote:
> Thank you Paul for your reply.
>
> FYI - I use Map not to use DTO - I put all properties (Long, Date) to
> this Map.
>
> So I have another question --- is it any way to define what kind of
> objects (Date, Long, Double, etc.) can show in Map. I found
> information @gwt.typeArgs <something>.
> I mean - is it possible to add to the remote interface information
> about all serializaed types which can be in Map? - to solve this
> problem
>
> Thanks,
> Krisw
>
>
> On 11 Mar, 17:55, Paul Robinson <ukcue...@gmail.com> wrote:
>   
>> kriswpl wrote:
>>     
>>> Interface method is:
>>> public Map<String, Object> test();
>>>       
>>> and in implementation I put into returned map, object java.util.Long
>>> (which is serializable:) ):
>>> map.put("long", new Long(1));
>>>       
>>> Where do I do it wrong?
>>>       
>> GWT does a great job of putting as little into the javascript as
>> possible. In the above case, there's nothing to tell it that you're
>> going to send a Long, so it doesn't generate the RPC code into the
>> javascript that knows how to deserialize a Long. Add another method that
>> references Long, and then your first method might work because the Long
>> code is now going to be included.
>>
>> On a related note, using Map in the API is not a good idea because it
>> means GWT must look through all your code for every implementation of
>> Map to see whether it's used. At the very least, it will make compiles
>> take longer. At worst, it will generate longer code. It goes against the
>> grain for java programming, but you need to make GWT RPC APIs as
>> specific as possible. That means declaring that you're returning a
>> HashMap, not a Map, in the interface.
>>
>> This also means you can't declare Object as a type in an RPC interface.
>>
>> Paul
>>     
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to