Unverified Commit 0eccb595 authored by ASobolewski's avatar ASobolewski Committed by GitHub
Browse files

Added option to preserve underscores in the JacksonJsonEnumHelper to fix...

Added option to preserve underscores in the JacksonJsonEnumHelper to fix TargetType.MERGE_REQUEST value. (#615)
parent 79493ea1
...@@ -466,7 +466,7 @@ public interface Constants { ...@@ -466,7 +466,7 @@ public interface Constants {
ISSUE, MILESTONE, MERGE_REQUEST, NOTE, PROJECT, SNIPPET, USER; ISSUE, MILESTONE, MERGE_REQUEST, NOTE, PROJECT, SNIPPET, USER;
private static JacksonJsonEnumHelper<TargetType> enumHelper = new JacksonJsonEnumHelper<>(TargetType.class, true, true); private static JacksonJsonEnumHelper<TargetType> enumHelper = new JacksonJsonEnumHelper<>(TargetType.class, true, false, true);
@JsonCreator @JsonCreator
public static TargetType forValue(String value) { public static TargetType forValue(String value) {
......
...@@ -32,6 +32,10 @@ public class JacksonJsonEnumHelper<E extends Enum<E>> { ...@@ -32,6 +32,10 @@ public class JacksonJsonEnumHelper<E extends Enum<E>> {
} }
public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized, boolean camelCased) { public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized, boolean camelCased) {
this(enumType, firstLetterCapitalized, camelCased, false);
}
public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized, boolean camelCased, boolean preserveUnderscores) {
valuesMap = new HashMap<>(); valuesMap = new HashMap<>();
namesMap = new HashMap<>(); namesMap = new HashMap<>();
...@@ -43,10 +47,14 @@ public class JacksonJsonEnumHelper<E extends Enum<E>> { ...@@ -43,10 +47,14 @@ public class JacksonJsonEnumHelper<E extends Enum<E>> {
boolean nextCharIsCapitalized = firstLetterCapitalized; boolean nextCharIsCapitalized = firstLetterCapitalized;
for (char ch : chars) { for (char ch : chars) {
if (ch == '_') { if (ch == '_') {
if (camelCased) { if (preserveUnderscores) {
nextCharIsCapitalized = true; nameBuf.append(ch);
} else { } else {
nameBuf.append(' '); if (camelCased) {
nextCharIsCapitalized = true;
} else {
nameBuf.append(' ');
}
} }
} else if (nextCharIsCapitalized) { } else if (nextCharIsCapitalized) {
nextCharIsCapitalized = false; nextCharIsCapitalized = false;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"project_id": 15, "project_id": 15,
"action_name": "pushed", "action_name": "pushed",
"target_id": 830, "target_id": 830,
"target_type": "MergeRequest", "target_type": "Merge_request",
"author_id": 1, "author_id": 1,
"author": { "author": {
"name": "Dmitriy Zaporozhets", "name": "Dmitriy Zaporozhets",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment