padcom/grails-json-rest-api — Issue #7: MongoDB
Author: ssxenon01
Created: 2011-11-11 03:19:14+00:00
State: open

Here is a little issue with mongoDB bson.types.ObjectID
and currently it using only number as a key object.

package org.grails.plugins.rest;

import java.beans.PropertyEditorSupport;

public class NumberToDomainInstanceEditor extends PropertyEditorSupport {
private final Class domainClass

public NumberToDomainInstanceEditor(Class domainClass) {
this.domainClass = domainClass
}

@Override
public void setValue(Object value) {
if (value.class == domainClass)
super.setValue(value)
else if (value instanceof Number) { // here it's only checking number
def instance = domainClass.get(value)
super.setValue(instance)
}
}
}

Sorry for my bad english