Skip to content

Allow field names and map keys with dot (.) #4464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
christophstrobl opened this issue Jul 31, 2023 · 0 comments
Closed

Allow field names and map keys with dot (.) #4464

christophstrobl opened this issue Jul 31, 2023 · 0 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@christophstrobl
Copy link
Member

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.

@christophstrobl christophstrobl added the type: enhancement A general enhancement label Jul 31, 2023
@sxhinzvc sxhinzvc self-assigned this Aug 3, 2023
@sxhinzvc sxhinzvc assigned christophstrobl and unassigned sxhinzvc Aug 31, 2023
@mp911de mp911de changed the title Allow field names and map keys with dot. Allow field names and map keys with dot (.) Oct 9, 2023
@mp911de mp911de changed the title Allow field names and map keys with dot (.) Allow field names and map keys with dot (.) Oct 9, 2023
@mp911de mp911de added this to the 4.2 RC1 (2023.1.0) milestone Oct 9, 2023
@mp911de mp911de closed this as completed in 691fc05 Oct 9, 2023
mp911de added a commit that referenced this issue Oct 9, 2023
Replace duplicate occurrences of _id with FieldName.ID.name(). Shorten property names to avoid repetative "field" wording. Add Javadoc
to MongoField builder.

See #4464
Original pull request: #4512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
3 participants