Skip to content
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

CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES doesn't work in special case #1026

Closed
snarayanank2 opened this issue Nov 29, 2015 · 7 comments
Closed

Comments

@snarayanank2
Copy link

I have a class with a property that looks like this:

class User {
  private String uId;
}

When I use the CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES naming strategy, this results in JSON with uid. However, if I change the variable name to usId, it results in us_id.

In general, it appears that if the first character is lower case and second is upper case, the naming strategy appears to not work as I'd expect. Any way around this?

I'm using jackson-databind-2.6.1 with DropWizard.

@cowtowncoder
Copy link
Member

To me this sounds like a bug, so a Pull Request for fix (and test that shows the initial problem) would be welcome.

@cowtowncoder
Copy link
Member

Unfortunately I can not reproduce this problem either with 2.6 branch (pre-2.6.4) or master (2.7.0-rc1), with property id of "uId" -- I get "u_id" as expected. So I think I would need a stand-alone unit test.

One thing to note is that Dropwizard has its own "snake case" annotation, I think, which uses different naming strategy implementation. Perhaps that could be causing the problem?

@snarayanank2
Copy link
Author

That is interesting! I'm not able to repro it in a standalone fashion. Looks like Dropwizard might be messing things up somewhere. I'll do some more investigation. Edit: see below

@snarayanank2
Copy link
Author

Here's a gist repro of the problem. It doesn't have anything to do with Dropwizard.

Looks like this doesn't have anything to do with Dropwizard. Actually, turns out it doesn't have to do with the variable name, but the getter function. In the gist, testCaseNoGetter passes (produces u_id) and testCaseGetter fails (produces uid).

Is this expected behavior? What should I name the getter to get the u_id in json?

@snarayanank2
Copy link
Author

If I name the getter:

    public String getuId() { return uId; }

Then I get u_id in the JSON.

@snarayanank2
Copy link
Author

So history is that I was using Project Lombok to generate my getters and setters and it looks like it uses a different naming convention for getters. See small print section in this doc. I've filed an issue with Lombok in case someone runs into this in the future.

Looks like this isn't a Jackson bug after all :) Sorry for the trouble - please feel free to close the issue.

@cowtowncoder
Copy link
Member

@snarayanank2 No problem. One related thing, for future reference, is that Jackson also has a minor deviation from standard Bean naming (it is lower-casing multiple leading upper-case letters, instead of leaving them as-is -- affects things like "getURL").
If this is what happens here, you may want to enable MapperFeature.USE_STD_BEAN_NAMING, which changes the behavior in this regard. I guess it may not be directly related, but might be good thing to be aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants