Skip to content

Add support for kotlin immutable collections with a backing mutable collection [DATAMONGO-2229] #3093

Open
@spring-projects-issues

Description

@spring-projects-issues

Knut Schleßelmann opened DATAMONGO-2229 and commented

Currently I'm struggling with the design of some aggregates in kotlin.

I'd like to have a collection exposed as a property but I need the mutable collection to handle things internally. AFAIK the current way to go in kotlin would be

@Document
class Product(
        @Id val id: String,
        attributes: Set<String> = emptySet()
) {

    private val _attributes: MutableSet<String> = attributes.toMutableSet()
    val attributes: Set<String>
        get() = _attributes
}

Sadly this fails because Spring Data Mongo cannot bind the document to my class any more. Even if I annotate _attributes with @Field("attributes") the constructor parameter is only used to determine the property field name (which then doesn't match again).

I'd be great to have better support for such use cases which do not involve hacks using the @Value("#root...") on properties or naming constructor arguments like some internal private field


Affects: 2.1.5 (Lovelace SR5)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions