0

I have some HashMap:

Map<SearchConfig, Object> searchParams;

There Object can be as simple type, such as String, or he can be simple entity:

public class SearchDataEntity implements Serializable  {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public SearchDataEntity() {}

    private String startDate;

    private String endDate;

    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }
}

When I send this to the server I have SerializationException.

If I send SearchDataEntity separately from Map it's OK.

4
  • Is SearchConfig class Serializable as well? Commented Jul 15, 2014 at 15:43
  • Yes SearchConfig no problem Commented Jul 15, 2014 at 15:50
  • Maybe you're storing a non Serializable object in your map. Commented Jul 15, 2014 at 15:51
  • please share a complete minimal testable code if possible. Commented Jul 15, 2014 at 15:52

1 Answer 1

4

You tell the GWT compiler that a Map will contain an Object. Then you try to pass a String or a SearchDataEntity instead of an Object. The compiler did not expect that, and it did not include a way to process a String or a SearchDataEntity in this serialization policy.

Think of it this way: if you specify "Animal" instead of "Dog" for your Map, the compiler will not know how to process the method isBarking() when you pass a Dog object.

You need to use specific HashMap<SearchConfig, SearchDataEntity> or HashMap<SearchConfig, String> in your RPC calls.

On a separate note, the best practice is to use HashMap instead of Map for RPC calls. Again, the compiler tries to include as little code as possible. By specifying Map you force a compiler to do more work than necessary (it has to look for each case where this Map is used to see what implementations may be required), and it might results in a larger code than necessary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.