Skip to content

MongoConverter mapkeydotreplacement does not work with nested documents [DATAMONGO-2636] #3489

Open
@spring-projects-issues

Description

@spring-projects-issues

Satish opened DATAMONGO-2636 and commented

Trying to insert a json into mongodb, however the json has nested json objects which has a dot(.) in the key.

Creating a MappingMongoConverter and providing a replacement does not work for nested documents

Example:

val converter = new MappingMongoConverter(new DefaultDbRefResolver(dbFactory), new MongoMappingContext)
 converter.setMapKeyDotReplacement("-")

val mongo = new MongoTemplate(dbFactory,converter)

var jsonmessage = "\{\"timestamp\": 1594313810768, \"status\": \"SUCCESS\", \"service.config\": {\"service.code\": \"SA30\"}}"

val doc = Document.parse(jsonmessage)

mongo.insert(doc, ""test_doc")

 
The above fails as it only changes dot on the top level (service.config) but does not replace at the nested level(service.code).

However parsing into a BasicDBObject seems to work

This works:

val doc = BasicDBObject.parse(jsonmessage)

mongo.insert(doc, ""test_doc")

 

It seems like Document is treated as a simple type and hence does not iterate into the nested documents.

Is there any alternative for this to work with Document?


No further details from DATAMONGO-2636

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions