Skip to content

Commit 6ad1f81

Browse files
Fix unhandled Accounting enums (#25)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent 6b28d04 commit 6ad1f81

File tree

6 files changed

+196
-14
lines changed

6 files changed

+196
-14
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ publishing {
4040
maven(MavenPublication) {
4141
groupId = 'dev.merge'
4242
artifactId = 'merge-java-client'
43-
version = '1.0.0'
43+
version = '1.0.1'
4444
from components.java
4545
}
4646
}

src/main/java/com/merge/api/core/ClientOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private ClientOptions(
2323
this.headers = new HashMap<>();
2424
this.headers.putAll(headers);
2525
this.headers.putAll(Map.of(
26-
"X-Fern-SDK-Name", "com.merge.fern:api-sdk", "X-Fern-SDK-Version", "1.0.0", "X-Fern-Language", "JAVA"));
26+
"X-Fern-SDK-Name", "com.merge.fern:api-sdk", "X-Fern-SDK-Version", "1.0.1", "X-Fern-Language", "JAVA"));
2727
this.headerSuppliers = headerSuppliers;
2828
this.httpClient = httpClient;
2929
;

src/main/java/com/merge/api/resources/accounting/types/ExpenseLineRequest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class ExpenseLineRequest {
2828

2929
private final Optional<String> company;
3030

31-
private final Optional<CurrencyEnum> currency;
31+
private final Optional<ExpenseLineRequestCurrency> currency;
3232

3333
private final Optional<ExpenseLineRequestAccount> account;
3434

@@ -49,7 +49,7 @@ private ExpenseLineRequest(
4949
Optional<ExpenseLineRequestTrackingCategory> trackingCategory,
5050
Optional<List<Optional<ExpenseLineRequestTrackingCategoriesItem>>> trackingCategories,
5151
Optional<String> company,
52-
Optional<CurrencyEnum> currency,
52+
Optional<ExpenseLineRequestCurrency> currency,
5353
Optional<ExpenseLineRequestAccount> account,
5454
Optional<ExpenseLineRequestContact> contact,
5555
Optional<String> description,
@@ -425,7 +425,7 @@ public Optional<String> getCompany() {
425425
* </ul>
426426
*/
427427
@JsonProperty("currency")
428-
public Optional<CurrencyEnum> getCurrency() {
428+
public Optional<ExpenseLineRequestCurrency> getCurrency() {
429429
return currency;
430430
}
431431

@@ -535,7 +535,7 @@ public static final class Builder {
535535

536536
private Optional<String> company = Optional.empty();
537537

538-
private Optional<CurrencyEnum> currency = Optional.empty();
538+
private Optional<ExpenseLineRequestCurrency> currency = Optional.empty();
539539

540540
private Optional<ExpenseLineRequestAccount> account = Optional.empty();
541541

@@ -636,12 +636,12 @@ public Builder company(String company) {
636636
}
637637

638638
@JsonSetter(value = "currency", nulls = Nulls.SKIP)
639-
public Builder currency(Optional<CurrencyEnum> currency) {
639+
public Builder currency(Optional<ExpenseLineRequestCurrency> currency) {
640640
this.currency = currency;
641641
return this;
642642
}
643643

644-
public Builder currency(CurrencyEnum currency) {
644+
public Builder currency(ExpenseLineRequestCurrency currency) {
645645
this.currency = Optional.of(currency);
646646
return this;
647647
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.merge.api.resources.accounting.types;
2+
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
import com.fasterxml.jackson.core.JsonParseException;
5+
import com.fasterxml.jackson.core.JsonParser;
6+
import com.fasterxml.jackson.databind.DeserializationContext;
7+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
8+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
9+
import com.merge.api.core.ObjectMappers;
10+
import java.io.IOException;
11+
import java.util.Objects;
12+
13+
@JsonDeserialize(using = ExpenseLineRequestCurrency.Deserializer.class)
14+
public final class ExpenseLineRequestCurrency {
15+
private final Object value;
16+
17+
private final int type;
18+
19+
private ExpenseLineRequestCurrency(Object value, int type) {
20+
this.value = value;
21+
this.type = type;
22+
}
23+
24+
@JsonValue
25+
public Object get() {
26+
return this.value;
27+
}
28+
29+
public <T> T visit(Visitor<T> visitor) {
30+
if (this.type == 0) {
31+
return visitor.visit((CurrencyEnum) this.value);
32+
} else if (this.type == 1) {
33+
return visitor.visit((String) this.value);
34+
}
35+
throw new IllegalStateException("Failed to visit value. This should never happen.");
36+
}
37+
38+
@Override
39+
public boolean equals(Object other) {
40+
if (this == other) return true;
41+
return other instanceof ExpenseLineRequestCurrency && equalTo((ExpenseLineRequestCurrency) other);
42+
}
43+
44+
private boolean equalTo(ExpenseLineRequestCurrency other) {
45+
return value.equals(other.value);
46+
}
47+
48+
@Override
49+
public int hashCode() {
50+
return Objects.hash(this.value);
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return this.value.toString();
56+
}
57+
58+
public static ExpenseLineRequestCurrency of(CurrencyEnum value) {
59+
return new ExpenseLineRequestCurrency(value, 0);
60+
}
61+
62+
public static ExpenseLineRequestCurrency of(String value) {
63+
return new ExpenseLineRequestCurrency(value, 1);
64+
}
65+
66+
public interface Visitor<T> {
67+
T visit(CurrencyEnum value);
68+
69+
T visit(String value);
70+
}
71+
72+
static final class Deserializer extends StdDeserializer<ExpenseLineRequestCurrency> {
73+
Deserializer() {
74+
super(ExpenseLineRequestCurrency.class);
75+
}
76+
77+
@Override
78+
public ExpenseLineRequestCurrency deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
79+
Object value = p.readValueAs(Object.class);
80+
try {
81+
return of(ObjectMappers.JSON_MAPPER.convertValue(value, CurrencyEnum.class));
82+
} catch (IllegalArgumentException e) {
83+
}
84+
try {
85+
return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class));
86+
} catch (IllegalArgumentException e) {
87+
}
88+
throw new JsonParseException(p, "Failed to deserialize");
89+
}
90+
}
91+
}

src/main/java/com/merge/api/resources/accounting/types/Invoice.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class Invoice {
4343

4444
private final Optional<Double> subTotal;
4545

46-
private final Optional<InvoiceStatusEnum> status;
46+
private final Optional<InvoiceStatus> status;
4747

4848
private final Optional<Double> totalTaxAmount;
4949

@@ -91,7 +91,7 @@ private Invoice(
9191
Optional<String> exchangeRate,
9292
Optional<Double> totalDiscount,
9393
Optional<Double> subTotal,
94-
Optional<InvoiceStatusEnum> status,
94+
Optional<InvoiceStatus> status,
9595
Optional<Double> totalTaxAmount,
9696
Optional<Double> totalAmount,
9797
Optional<Double> balance,
@@ -565,7 +565,7 @@ public Optional<Double> getSubTotal() {
565565
* </ul>
566566
*/
567567
@JsonProperty("status")
568-
public Optional<InvoiceStatusEnum> getStatus() {
568+
public Optional<InvoiceStatus> getStatus() {
569569
return status;
570570
}
571571

@@ -787,7 +787,7 @@ public static final class Builder {
787787

788788
private Optional<Double> subTotal = Optional.empty();
789789

790-
private Optional<InvoiceStatusEnum> status = Optional.empty();
790+
private Optional<InvoiceStatus> status = Optional.empty();
791791

792792
private Optional<Double> totalTaxAmount = Optional.empty();
793793

@@ -1001,12 +1001,12 @@ public Builder subTotal(Double subTotal) {
10011001
}
10021002

10031003
@JsonSetter(value = "status", nulls = Nulls.SKIP)
1004-
public Builder status(Optional<InvoiceStatusEnum> status) {
1004+
public Builder status(Optional<InvoiceStatus> status) {
10051005
this.status = status;
10061006
return this;
10071007
}
10081008

1009-
public Builder status(InvoiceStatusEnum status) {
1009+
public Builder status(InvoiceStatus status) {
10101010
this.status = Optional.of(status);
10111011
return this;
10121012
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.merge.api.resources.accounting.types;
2+
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
import com.fasterxml.jackson.core.JsonParseException;
5+
import com.fasterxml.jackson.core.JsonParser;
6+
import com.fasterxml.jackson.databind.DeserializationContext;
7+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
8+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
9+
import com.merge.api.core.ObjectMappers;
10+
import java.io.IOException;
11+
import java.util.Objects;
12+
13+
@JsonDeserialize(using = InvoiceStatus.Deserializer.class)
14+
public final class InvoiceStatus {
15+
private final Object value;
16+
17+
private final int type;
18+
19+
private InvoiceStatus(Object value, int type) {
20+
this.value = value;
21+
this.type = type;
22+
}
23+
24+
@JsonValue
25+
public Object get() {
26+
return this.value;
27+
}
28+
29+
public <T> T visit(Visitor<T> visitor) {
30+
if (this.type == 0) {
31+
return visitor.visit((InvoiceStatusEnum) this.value);
32+
} else if (this.type == 1) {
33+
return visitor.visit((String) this.value);
34+
}
35+
throw new IllegalStateException("Failed to visit value. This should never happen.");
36+
}
37+
38+
@Override
39+
public boolean equals(Object other) {
40+
if (this == other) return true;
41+
return other instanceof InvoiceStatus && equalTo((InvoiceStatus) other);
42+
}
43+
44+
private boolean equalTo(InvoiceStatus other) {
45+
return value.equals(other.value);
46+
}
47+
48+
@Override
49+
public int hashCode() {
50+
return Objects.hash(this.value);
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return this.value.toString();
56+
}
57+
58+
public static InvoiceStatus of(InvoiceStatusEnum value) {
59+
return new InvoiceStatus(value, 0);
60+
}
61+
62+
public static InvoiceStatus of(String value) {
63+
return new InvoiceStatus(value, 1);
64+
}
65+
66+
public interface Visitor<T> {
67+
T visit(InvoiceStatusEnum value);
68+
69+
T visit(String value);
70+
}
71+
72+
static final class Deserializer extends StdDeserializer<InvoiceStatus> {
73+
Deserializer() {
74+
super(InvoiceStatus.class);
75+
}
76+
77+
@Override
78+
public InvoiceStatus deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
79+
Object value = p.readValueAs(Object.class);
80+
try {
81+
return of(ObjectMappers.JSON_MAPPER.convertValue(value, InvoiceStatusEnum.class));
82+
} catch (IllegalArgumentException e) {
83+
}
84+
try {
85+
return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class));
86+
} catch (IllegalArgumentException e) {
87+
}
88+
throw new JsonParseException(p, "Failed to deserialize");
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)