Skip to content

Commit

Permalink
- Fix ID field usage in string representation of EasyPost objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Apr 9, 2024
1 parent 9ea0bce commit 3eb1051
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Next Release

- Fix payment method funding and deletion failures due to undetermined payment method type
- Adds `refund` function in Insurance service for requesting a refund for a standalone insurance
- Fix payment method funding and deletion failures due to undetermined payment method type
- Fix `toString` method for all EasyPost models

## v7.1.1 (2024-03-21)

Expand Down
30 changes: 6 additions & 24 deletions src/main/java/com/easypost/model/EasyPostResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package com.easypost.model;

import java.lang.reflect.Field;

import java.util.Date;

import com.easypost.Constants;
Expand All @@ -30,27 +28,10 @@ public abstract class EasyPostResource {
*/
@Override
public String toString() {
return (String) this.getIdString();
}

/**
* Get the ID of the object.
*
* @return ID of the object.
*/
private Object getIdString() {
try {
Field idField = this.getClass().getDeclaredField("id");
return idField.get(this);
} catch (SecurityException e) {
return "";
} catch (NoSuchFieldException e) {
return "";
} catch (IllegalArgumentException e) {
return "";
} catch (IllegalAccessException e) {
return "";
if (this.id == null) {
return String.format("<%s@%s>", this.getClass().getName(), System.identityHashCode(this));
}
return String.format("<%s@%s id=%s>", this.getClass().getName(), System.identityHashCode(this), this.id);
}

/**
Expand All @@ -59,8 +40,9 @@ private Object getIdString() {
* @return the JSON representation of the object.
*/
public String prettyPrint() {
return String.format("<%s@%s id=%s> JSON: %s", this.getClass().getName(), System.identityHashCode(this),
this.getIdString(), Constants.Http.PRETTY_PRINT_GSON.toJson(this));
String identifier = this.toString();
String json = Constants.Http.PRETTY_PRINT_GSON.toJson(this);
return String.format("%s JSON: %s", identifier, json);
}

/**
Expand Down

0 comments on commit 3eb1051

Please sign in to comment.