public boolean marshall(Resource resource, Object root, Mapping mapping, MarshallingContext context) throws ConversionException {
if (root == null) {
return false;
}
ResourcePropertyMapping resourcePropertyMapping = (ResourcePropertyMapping) mapping;
Map map = (Map) root;
Set entries;
try {
entries = map.entrySet();
} catch (NullPointerException ex) {
// this can happen with Hibernate when cascading the delete from an owner of a Map<String, String>
// see http://jira.codehaus.org/browse/GRAILSPLUGINS-482
return false;
}
for (Iterator it = entries.iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Property p = context.getResourceFactory().createProperty(entry.getKey().toString(), entry.getValue().toString(),
resourcePropertyMapping.getStore(), resourcePropertyMapping.getIndex(), resourcePropertyMapping.getTermVector());
p.setBoost(resourcePropertyMapping.getBoost());
resource.addProperty(p);
}
if (supportUnmarshall) {
String stringmap = DefaultGroovyMethods.inspect(map);
InternalCompassSession compassSession = context.getSession();
InternalCompass compass = compassSession.getCompass();
SearchEngineFactory searchEngineFactory = compass.getSearchEngineFactory();
PropertyNamingStrategy propertyNamingStrategy =
searchEngineFactory.getPropertyNamingStrategy();
// save stringifiedmap map (under an internal name)
String keyPath = propertyNamingStrategy.buildPath(resourcePropertyMapping.getPath(), "stringmap").getPath();
Property p = context.getResourceFactory().createProperty(keyPath, stringmap, Property.Store.YES, Property.Index.NOT_ANALYZED);
resource.addProperty(p);
}
return true;