Skip to content

Commit 932d118

Browse files
[Bugfix][VAPI-2447] - Added XML Adapter to parse the enum as an enum string value instead of enum name
1 parent 935ee19 commit 932d118

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/com/bandwidth/sdk/model/CallDirectionEnum.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.gson.annotations.JsonAdapter;
2323
import com.google.gson.stream.JsonReader;
2424
import com.google.gson.stream.JsonWriter;
25+
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
2526

2627
/**
2728
* The direction of the call.
@@ -33,7 +34,7 @@ public enum CallDirectionEnum {
3334

3435
OUTBOUND("outbound");
3536

36-
private String value;
37+
private final String value;
3738

3839
CallDirectionEnum(String value) {
3940
this.value = value;
@@ -45,7 +46,7 @@ public String getValue() {
4546

4647
@Override
4748
public String toString() {
48-
return String.valueOf(value);
49+
return value;
4950
}
5051

5152
public static CallDirectionEnum fromValue(String value) {
@@ -70,6 +71,24 @@ public CallDirectionEnum read(final JsonReader jsonReader) throws IOException {
7071
}
7172
}
7273

74+
public static class XMLAdapter extends XmlAdapter<String, CallDirectionEnum> {
75+
@Override
76+
public CallDirectionEnum unmarshal(String v) {
77+
for (CallDirectionEnum e : CallDirectionEnum.values()) {
78+
if (e.toString().equals(v)) {
79+
return e;
80+
}
81+
}
82+
return null;
83+
}
84+
85+
@Override
86+
public String marshal(CallDirectionEnum v) {
87+
return v.toString();
88+
}
89+
}
90+
91+
7392
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
7493
String value = jsonElement.getAsString();
7594
CallDirectionEnum.fromValue(value);

src/main/java/com/bandwidth/sdk/model/bxml/StartStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.bandwidth.sdk.model.CallDirectionEnum;
1919

20+
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
2021
import lombok.AllArgsConstructor;
2122
import lombok.Builder;
2223
import lombok.Builder.Default;
@@ -83,6 +84,7 @@ public class StartStream implements Verb {
8384
protected String mode;
8485

8586
@XmlAttribute
87+
@XmlJavaTypeAdapter(CallDirectionEnum.XMLAdapter.class)
8688
@Default
8789
protected CallDirectionEnum tracks = CallDirectionEnum.INBOUND;
8890

0 commit comments

Comments
 (0)