Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Jan 8, 2025
1 parent 6a42a4e commit 041ca67
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 97 deletions.
3 changes: 3 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Specify files that shouldn't be modified by Fern

src/main/java/com/flatfile/api/resources/records/types/CellValueUnion.java
src/main/java/com/flatfile/api/resources/snapshots/SnapshotsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
package com.flatfile.api.resources.records.types;

import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
Expand All @@ -11,103 +16,10 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.flatfile.api.core.ObjectMappers;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Objects;

@JsonDeserialize(using = CellValueUnion.Deserializer.class)
public final class CellValueUnion {
private final Object value;

private final int type;

private CellValueUnion(Object value, int type) {
this.value = value;
this.type = type;
}

@JsonValue
public Object get() {
return this.value;
}

public <T> T visit(Visitor<T> visitor) {
if (this.type == 0) {
return visitor.visit((String) this.value);
} else if (this.type == 1) {
return visitor.visit((int) this.value);
} else if (this.type == 2) {
return visitor.visit((long) this.value);
} else if (this.type == 3) {
return visitor.visit((double) this.value);
} else if (this.type == 4) {
return visitor.visit((boolean) this.value);
} else if (this.type == 5) {
return visitor.visit((String) this.value);
} else if (this.type == 6) {
return visitor.visit((OffsetDateTime) this.value);
} else if (this.type == 7) {
return visitor.visit((List<String>) this.value);
}
throw new IllegalStateException("Failed to visit value. This should never happen.");
}

@java.lang.Override
public boolean equals(Object other) {
if (this == other) return true;
return other instanceof CellValueUnion && equalTo((CellValueUnion) other);
}

private boolean equalTo(CellValueUnion other) {
return value.equals(other.value);
}

@java.lang.Override
public int hashCode() {
return Objects.hash(this.value);
}

@java.lang.Override
public String toString() {
return this.value.toString();
}

public static CellValueUnion of(String value) {
return new CellValueUnion(value, 0);
}

public static CellValueUnion of(int value) {
return new CellValueUnion(value, 1);
}

public static CellValueUnion of(long value) {
return new CellValueUnion(value, 2);
}

public static CellValueUnion of(double value) {
return new CellValueUnion(value, 3);
}

public static CellValueUnion of(boolean value) {
return new CellValueUnion(value, 4);
}

public static CellValueUnion of(String value) {
return new CellValueUnion(value, 5);
}

public static CellValueUnion of(OffsetDateTime value) {
return new CellValueUnion(value, 6);
}

public static CellValueUnion of(List<String> value) {
return new CellValueUnion(value, 7);
}

public interface Visitor<T> {
T visit(String value);

T visit(int value);

T visit(long value);
Expand Down Expand Up @@ -156,10 +68,95 @@ public CellValueUnion deserialize(JsonParser p, DeserializationContext ctxt) thr
} catch (IllegalArgumentException e) {
}
try {
return of(ObjectMappers.JSON_MAPPER.convertValue(value, new TypeReference<List<String>>() {}));
return of(ObjectMappers.JSON_MAPPER.convertValue(value, new TypeReference<List<String>>() {
}));
} catch (IllegalArgumentException e) {
}
throw new JsonParseException(p, "Failed to deserialize");
}
}

public static CellValueUnion of(String value) {
return new CellValueUnion(value, 0);
}

public static CellValueUnion of(int value) {
return new CellValueUnion(value, 1);
}

public static CellValueUnion of(long value) {
return new CellValueUnion(value, 2);
}

public static CellValueUnion of(double value) {
return new CellValueUnion(value, 3);
}

public static CellValueUnion of(boolean value) {
return new CellValueUnion(value, 4);
}

public static CellValueUnion of(OffsetDateTime value) {
return new CellValueUnion(value, 6);
}

public static CellValueUnion of(List<String> value) {
return new CellValueUnion(value, 7);
}

private final Object value;

private final int type;

private CellValueUnion(Object value, int type) {
this.value = value;
this.type = type;
}

@JsonValue
public Object get() {
return this.value;
}

public <T> T visit(Visitor<T> visitor) {
if (this.type == 0) {
return visitor.visit((String) this.value);
} else if (this.type == 1) {
return visitor.visit((int) this.value);
} else if (this.type == 2) {
return visitor.visit((long) this.value);
} else if (this.type == 3) {
return visitor.visit((double) this.value);
} else if (this.type == 4) {
return visitor.visit((boolean) this.value);
} else if (this.type == 5) {
return visitor.visit((String) this.value);
} else if (this.type == 6) {
return visitor.visit((OffsetDateTime) this.value);
} else if (this.type == 7) {
return visitor.visit((List<String>) this.value);
}
throw new IllegalStateException("Failed to visit value. This should never happen.");
}

@java.lang.Override
public boolean equals(Object other) {
if (this == other)
return true;
return other instanceof CellValueUnion && equalTo((CellValueUnion) other);
}

@java.lang.Override
public int hashCode() {
return Objects.hash(this.value);
}

@java.lang.Override
public String toString() {
return this.value.toString();
}

private boolean equalTo(CellValueUnion other) {
return value.equals(other.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
package com.flatfile.api.resources.snapshots;

import java.io.IOException;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.flatfile.api.core.ClientOptions;
import com.flatfile.api.core.FlatfileApiException;
Expand All @@ -23,8 +26,7 @@
import com.flatfile.api.resources.snapshots.types.RestoreOptions;
import com.flatfile.api.resources.snapshots.types.SnapshotResponse;
import com.flatfile.api.resources.snapshots.types.SnapshotsResponse;
import java.io.IOException;
import java.util.Optional;

import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -165,7 +167,7 @@ public SnapshotResponse getSnapshot(
.newBuilder()
.addPathSegments("snapshots")
.addPathSegment(snapshotId.toString());
httpUrl.addQueryParameter("includeSummary", request.getIncludeSummary().toString());
httpUrl.addQueryParameter("includeSummary", String.valueOf(request.getIncludeSummary()));
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
Expand Down

0 comments on commit 041ca67

Please sign in to comment.