Coder Social home page Coder Social logo

Comments (6)

rainerfrey avatar rainerfrey commented on July 19, 2024

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.

keeth avatar keeth commented on July 19, 2024

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.

nikomakela avatar nikomakela commented on July 19, 2024

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.

nikomakela avatar nikomakela commented on July 19, 2024

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:

from grails-data-mapping.

nikomakela avatar nikomakela commented on July 19, 2024

@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.

graemerocher avatar graemerocher commented on July 19, 2024

@nikomakela create a new issue and upload an example to github that reproduces the issue

from grails-data-mapping.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.