[JAVA-2615] Snake Case Created: 27/Sep/17  Updated: 11/Sep/19  Resolved: 08/Nov/17

Status: Closed
Project: Java Driver
Component/s: POJO
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Trivial - P5
Reporter: Aleksandr Blokh Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB java driver


Attachments: PNG File Screen Shot 2017-10-04 at 09.33.10.png    
Backwards Compatibility: Fully Compatible

 Description   

Hi, guys!

Struggling trying to find a default naming strategy config and seems like it just not there.

So if it's possible - would be very grateful for smthing like .setNamingStrategy(NamingStrategy.SNAKE_CASE..

Thx



 Comments   
Comment by Ross Lawley [ 05/Oct/17 ]

Hi alex.blokh,

This would be easier to do with your own custom convention. Custom Conventions can easily be set globally via the PojoCodecProvider.Builder.conventions(conventions) method. See the conventions documentation.

The PojoCustomTest case has an example of a custom convention that looks like it could suit your needs. Just don't forget to also include the default conventions.

I hope that helps,

Ross

Comment by Aleksandr Blokh [ 04/Oct/17 ]

Yes, I'm talking about field names in documents

Now, if I have a camelCase field name in java -> it goes the same camelCase key name to a mongodb document
And the only possible way I found to change that behavior is to annotate field with

@BsonProperty(value = "snake_case_key")


That's why I was looking for a solution of a global configuration of naming strategy.

For example Jackson library has ObjectMapper with a

objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)

It's fairly straightforward.

If that's possible with a convention it would be very helpful to write a snippet in documentation on that. Cause I found nothing on stackoverflow about that

Thanks a lot, guys!

Comment by Ross Lawley [ 28/Sep/17 ]

Hi alex.blokh,

Please could you add some context to the ticket, I'm unclear as to what exactly you are asking for. If it's regarding field names in Documents then they are set on insertion. If this is regarding the POJO Codec then you should add a custom convention to change the read and write property names to the format you require.

All the best,

Ross

Generated at Thu Feb 08 08:57:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.