Description
MongoDB 5 relaxed restrictions on special characters in field names as outlined in the reference documentation.
{
"_id" : "id-1",
"key.with.dot" : "value",
"mapValue" : {
"map.key.with.dot" : "mv"
}
}
class WithMap {
String id;
@Field("key.with.dot")
String value;
Map<String, String> mapValue;
}
By default the mapping layer will able to read the above structure but reject map keys not having a mapKeyDotReplacement
set on write. Users may use .
as the replacement value to able to write map.key.with.dot
from the above example. Still the dot notation within the value of an @Field
annotation has a different semantic that would expand the parts of the field name into separate nested documents.
{
"_id" : "id-1",
"key" : { "with" : { "dot" : "value" } },
"mapValue" : {
"map.key.with.dot" : "mv"
}
}
One way of dealing with this issue could be to enhance the @Field
annotation as follows:
public @interface Field {
Class<? extends FieldNamingStrategy> fieldNaming() default FieldNamingStrategy.class;
// ...
}
this would allow a certain level of flexibility eg. by providing predefined strategies for the above purpose as well as having a fixed value for meta annotation usage.