1

I'm trying to map json strings that use underscore naming convention to their corresponding java objects, the problem is the getters and setters get messy. For example

public static class ChargeState{

    private String charging_state;

    public String getCharging_state() {
        return charging_state;
    }
}

But what I want eclipse to generate

 public String getChargingState() {
        return charging_state;
    }

When I go into the preferences there is Java->Code Style->Code Templates

then for the setter body option it says ${field} = ${param};

Can i change this pattern or something to remove the underscore?

Brian
  • 4,328
  • 13
  • 58
  • 103
  • 1
    possible duplicate of [Getters and Setters in Eclipse for Hungarian Style Members](http://stackoverflow.com/questions/7784103/getters-and-setters-in-eclipse-for-hungarian-style-members) – ChiefTwoPencils Jun 30 '14 at 00:22
  • 1
    It's not a duplicate, that is for having an underscore in the prefix of the variable. – Brian Jun 30 '14 at 00:24

1 Answers1

4

I think if you go to Window->Preferences->Java->Code Style and set the Fields prefix list to '_' you will probably be able to do what your trying to achieve. If this doesn't help, maybe try this past question

Community
  • 1
  • 1
lijrobert
  • 125
  • 2
  • 9
  • Unfortunately, both ways you mentioned solve only "underscore in prefix" case. Not in the middle of the field's name, as OP asks. – xmichael91 Aug 30 '17 at 14:03