Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support for immutable collection types [DATACMNS-1381] #1817

Open
Assignees
odrotbohm
Labels
in: mappingMapping and conversion infrastructuretype: enhancementA general enhancement
@spring-projects-issues

Description

@spring-projects-issues

John Butler openedDATACMNS-1381 and commented

Currently the MappingMongoConverter makes a static call toCollectionFactory.createCollection andCollectionFactory.createMap. And currentlyCollectionFactory does not support any of the Guava Immutable collection. Until Java comes up with a List interface that expresses that it is Immutable, I believe there is still good reason to declare class fields asImmutableList instead of justList. For this reason it would be create to provide a mechanism to support these collections:ImmutableList, ImmutableSet, ImmutableMultiSet, ImmutableMap, ImmutableBiMap.

In order to do this the create method would need to take a set of values to populated in the created collection or a Builder interface would need to be returned.

Use Case: I have a domain object as below...

publicclassMyDomain{privateList<String>listOfValues;}

I want the above to be thread-safe and so I design it to be immutable. When I create it I appropriate use ImmutableList. However, in the above there are two issues: 1) the getter returns List which gives the caller no indication that it is immutable 2) when marshalled via Spring Data it is created as a mutable List thereby breaking my thread-safety through immutability. Therefore the below would be better:

publicclassMyDomain{privateImmutableList<String>listOfValues;}

 


Issue Links:

  • SPR-16797 Allow creation of immutable collections through CollectionFactory

  • DATACMNS-1322 Add support for immutable objects in PersistentPropertyAccessor

1 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: mappingMapping and conversion infrastructuretype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp