Saturday, June 17, 2017

Annoying Map containing List bug

I've found a weird behavior of GWT.
I've a code that communicates with server side via RPC.

The request returns a Map<String, Object> wich runs fine. Until last week, when I spent about 3 days to figure that I can't put a List<Enum> in the map. The problem is not from Server side to Client side, but when the client side try to send the Map back to server side, it throws an error "this$static[signature][2] is not a function", without any clue about the problem.

the server side RPC code is similar to:

public Map<String, Object> getContext() {
  Map<String, Object> myMap = new HashMap<String, Object>();
  List<String> someStrings = new ArrayList<String>();
  List<String> otherStrings = new ArrayList<String>();
  List<SITUACAO> situacoes = new ArrayList<SITUACAO>();

  someStrings.add("Some strings to test");
  otherStrings.add("Other strings to test");
  situacoes.add(SITUACAO.NOVA);
  myMap.put("someString", someStrings);
  myMap.put("otherString", otherStrings);
  myMap.put("someConstant", situacoes);
  return myMap; 
}

The client side receives data, and show a dialog with that data. No error. But when I try to send the map back over the wire, I get the error.

Changing the code to:

public Map<String, Object> getContext() {
  Map<String, Object> myMap = new HashMap<String, Object>();
  List<String> someStrings = new ArrayList<String>();
  List<String> otherStrings = new ArrayList<String>();
  List<String> situacoes = new ArrayList<String>();

  someStrings.add("Some strings to test");
  otherStrings.add("Other strings to test");
  situacoes.add(SITUACAO.NOVA.name());
  myMap.put("someString", someStrings);
  myMap.put("otherString", otherStrings);
  myMap.put("someConstant", situacoes);
  return myMap; 
}

...is a workaround!

In time: before someone try to convince me that a Map<String,Object> is a bad idea, it is working really well - I've a system with about 500.000 lines of code, and I'll not change this.

If you need more details to fix this annoying bug, please let me know.

Regards,

Edson Richter

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment