Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use Siena model objects with Query fields on Groovy templates #5

Open
dmoebius opened this issue Oct 14, 2011 · 0 comments
Open

Comments

@dmoebius
Copy link

Consider the following model class:

@Table("units")
public class Unit extends Model {
  @Id public Long id;

  @Filter("unit")
  public Query<Entry> entries;
}

If you try to put an instance of this class into the params map and use it in a Groovy/HTML template:

public static void edit(Long unitId) {
  Unit unit = Unit.getByKey(unitId);
  notFoundIfNull(unit, "unit " + unitId);
  render(unit);
}
#{extends 'main.html' /}
#{set title:'Edit Unit ${unit.name}' /}
<h1>Edit Unit ${unit.name}</h1>

then Play fails to serialize ("unbind") the class because it runs into an infinite recursion when trying to serialize the Query field. Eventually it throws a StackOverflowException.

The reason is because Play serializes the Unit instance into a map of json keys like this:

unit.entries.obj = ...
unit.entries.obj.entries = ...
unit.entries.obj.entries.obj = ...
unit.entries.obj.entries.obj.entries = ...
unit.entries.obj.entries.obj.entries.obj = ...

... and so on forever.

A solution for the play-siena plugin might be to override the unBind() method in SienaPlugin to ignore Query fields altogether:

@Override
public Map<String, Object> unBind(Object src, String name) {
  if (siena.Query.class.isAssignableFrom(src.getClass())) {
    return new HashMap<String, Object>();
  }
  return null;
}

Please evaluate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant