Play Form serialization problem


(Kamil) #1

I have a form:

public class RatingForm {
  private Map<RatingCriterion, Integer> rates;
//setter&getter
}

When I serialize it:

  public Result test() {
    final Map<RatingCriterion, Integer> map = new HashMap<>();
    map.put(RatingCriterion.FOO, 4);
    map.put(RatingCriterion.BAR, 3);
    final RatingForm f = new RatingForm();
    f.setRates(map);
    final Form<RatingForm> form = formFactory.form(RatingForm.class).fill(f);

    return ok(Json.toJson(form.field("rates").getValue().orElse(null)));
  }

I get in response: "{FOO=4, BAR=3}"

while: return ok(Json.toJson(map)); returns "{FOO:4, BAR:3}"

Isn’t it a bug?