Well, you can have an implementation for PropertyNamingStrategy that looks something like this:
import org.codehaus.jackson.map.MapperConfig;
import org.codehaus.jackson.map.PropertyNamingStrategy;
import org.codehaus.jackson.map.introspect.AnnotatedField;
import org.codehaus.jackson.map.introspect.AnnotatedMethod;
public class CustomNameStrategy extends PropertyNamingStrategy {
@Override
public String nameForField(MapperConfig config, AnnotatedField field, String defaultName) {
return convert(defaultName);
}
@Override
public String nameForGetterMethod(MapperConfig config, AnnotatedMethod method, String defaultName) {
return convert(defaultName);
}
@Override
public String nameForSetterMethod(MapperConfig config, AnnotatedMethod method, String defaultName) {
return convert(defaultName);
}
public String convert(String defaultName) {
char[] arr = defaultName.toCharArray();
StringBuilder nameToReturn = new StringBuilder();
for (int i = 0; i < arr.length; i++) {
if (arr[i] == '_') {
nameToReturn.append(Character.toUpperCase(arr[i + 1]));
i++;
} else {
nameToReturn.append(arr[i]);
}
}
return nameToReturn.toString();
}
}
then in your implementation or the class that does the desrialization you can have:
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(new CustomNameStrategy());
YourClass yourClass = mapper.readValue(yourJsonString, YourClass.class);