Comments (6)
Presumably, the evaluation of a List as a Simple or Basic type supersedes the custom marshallers.
I'm having the same problem with a map. Your presumption seems to be right (as far as I understand the code while debugging). My workaround: my map doesn't actually implement java.util.Map (Collection in your case), but delegates to a map internally, and provides a necessary subset of Map's interface.
from grails-data-mapping.
I ran into a similar issue. marking the field as embedded fixed it.
class RegularPerson {
static embedded = ['birthday']
String name
Birthday birthday
}
from grails-data-mapping.
Did it also fix the list type, because I'm still having this in mongo-plugin version 3.0.3?
I've now tried with
class FormSubField extends HashMap<String, FormFieldList> implements Serializable {
}
and
class FormFieldList extends ArrayList<FormField> implements Serializable {
}
and with marshaller for custom list type
class FormFieldListType extends AbstractMappingAwareCustomTypeMarshaller<FormFieldList, DBObject, DBObject> {
FormFieldListType() {
super(FormFieldList)
println "super(FormFieldList)"
}
//...
}
Constructor is called, so it is registered properly, but writeInternal nor readInternal are never called!
from grails-data-mapping.
It seems like that embedded properties cannot have a custom type marshaller. WriteInternal is never called for embedded properties, but them are for basic types. I also made a test domain and tried to persist different kind of proeprties. It seems like only basic types are persisted in database.
class SubFieldTest {
static mapWith = "mongo"
static embedded = ['subFieldsMapEmbedded','subFieldMap', 'stringMap','mapsMapEmbedded','objectsMapEmbedded','mapsMapEmbeddedWithSetter']
Map<String, List<AbstractFormField>> subFieldsMapEmbedded
Map<String, List<Object>> objectsMapEmbedded
Map<String, List<Map>> mapsMapEmbedded
Map<String, List<AbstractFormField>> subFieldsMapNotEmbedded
Map<String, List<String>> stringMapEmbedded // Works
Map<String, AbstractFormField> subFieldMapEmbedded
Map<String, List<Map>> mapsMapEmbeddedWithSetter // Writing works, not reading from db
void setMapsMapEmbeddedWithSetter(Map<String, List<AbstractFormField>> valueMap){
def subFieldsValue = [:]
valueMap.each{ trigger, subFieldList ->
subFieldsValue[trigger] = subFieldList.collect{ instance ->
def map = [:]
println "instance.domainClass.persistentProperties: ${instance.domainClass.persistentProperties}"
instance.domainClass.persistentProperties.each{ persistentProperty ->
def value = instance.properties[persistentProperty.name]
if(value != null){
map[persistentProperty.name] = value
}
}
return map
}
}
this.mapsMapEmbeddedWithSetter = subFieldsValue
}
}
Some related links:
- http://stackoverflow.com/questions/11921985/how-to-support-embedded-maps-with-custom-value-types-in-mongodb-gorm
- https://github.com/grails/grails-data-mapping/blob/3.x/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/MappingFactory.java#L131
- http://stackoverflow.com/questions/14712428/grailsmongodb-cant-serialize-mapstring-enum
- http://springsource.github.io/grails-data-mapping/mongo/manual/guide/3.%20Mapping%20Domain%20Classes%20to%20Mongo%20Collections.html#3.6%20Custom%20User%20Types
from grails-data-mapping.
@divideby0 Have you found a solution to persist list of custom types? I would like to persist a map that contains a list of custom types as a value.
@graemerocher I don't think this is really fixed, because it seems like custom types are checked after simple types.
from grails-data-mapping.
@nikomakela create a new issue and upload an example to github that reproduces the issue
from grails-data-mapping.
Related Issues (20)
- DetachedCriteria disjunction HOT 1
- gradlew idea fails for grails-data-mapping HOT 1
- redis-gorm: Failed to convert from type java.lang.String to type java.lang.Long HOT 1
- [MongoDB] mongoTemplate created for every domain class
- Log4j seems to be using multiple versions
- simpledb plugin creates HiLo domain even if not used.
- simpledb: how to set region endpoint ? HOT 4
- hasMany doesn't support more than 20 records HOT 3
- sqlProjection not working in criteria query
- Wrong port number in the manual
- Developer Guide Page is Down HOT 2
- Improve Neo4j GraphDB usability for Groovy/Grails
- [GORM-Neo4j] ToOne's with same class spawn loops
- [GORM-Neo4j]: No Transactional context for services exist.
- Neo4j: Date properties cant' have null values
- Dependency resolution during SimpleDB plugin install fails HOT 1
- transient property not validating HOT 2
- How to use the withCriteria results in a new withCriteria query in Grails? HOT 3
- CouchDB Support
- [CORE] concurrentlinkedhashmap-lru:1.2_jdk5 dependency : conflicts with Neo4j 1.8.1+ HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grails-data-mapping.