diff --git a/src/main/java/io/ljunggren/usps/api/model/MailClass.java b/src/main/java/io/ljunggren/usps/api/model/MailClass.java deleted file mode 100644 index 7de3d6b..0000000 --- a/src/main/java/io/ljunggren/usps/api/model/MailClass.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.ljunggren.usps.api.model; - -public enum MailClass { - - PARCEL_SELECT("Parcel Select"), - PARCEL_SELECT_LIGHTWEIGHT("Parcel Select Lightweight"), - PRIORITY_MAIL_EXPRESS("Priority Mail Express"), - PRIORITY_MAIL("Priority Mail"), - FIRST_CLASS_PACKAGE_SERVICE("First Class Package Service"), - LIBRARY_MAIL("Library Mail"), - MEDIA_MAIL("Media Mail"), - BOUND_PRINTED_MATTER("Bound Printed Matter"), - USPS_CONNECT_LOCAL("USPS Connect Local"), - USPS_CONNECT_MAIL("USPS Connect Mail"), - USPS_CONNECT_REGIONAL("USPS Connect Regional"), - USPS_GROUND_ADVANTAGE("USPS Ground Advantage"), - USPS_RETAIL_GROUND("USPS_Retail Ground"), - ALL(""); - - private String text; - - private MailClass(String text) { - this.text = text; - } - - public String getText() { - return text; - } - -} diff --git a/src/main/java/io/ljunggren/usps/api/model/rate/Rate.java b/src/main/java/io/ljunggren/usps/api/model/rate/Rate.java index 6979bea..d141fad 100644 --- a/src/main/java/io/ljunggren/usps/api/model/rate/Rate.java +++ b/src/main/java/io/ljunggren/usps/api/model/rate/Rate.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; -import io.ljunggren.usps.api.model.MailClass; import io.ljunggren.usps.api.model.ProcessingCategory; import lombok.Data; @@ -18,7 +17,7 @@ private String priceType; private Double price; private String rateIndicator; - private MailClass mailClass; + private String mailClass; private ProcessingCategory processingCategory; private String productName; private String productDefinition; diff --git a/src/main/java/io/ljunggren/usps/api/model/rate/RateRequest.java b/src/main/java/io/ljunggren/usps/api/model/rate/RateRequest.java index a10d6bd..a577f72 100644 --- a/src/main/java/io/ljunggren/usps/api/model/rate/RateRequest.java +++ b/src/main/java/io/ljunggren/usps/api/model/rate/RateRequest.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.ljunggren.usps.api.model.AccountType; -import io.ljunggren.usps.api.model.MailClass; import io.ljunggren.usps.api.model.PriceType; import lombok.Data; @@ -23,14 +22,15 @@ private String originZipCode; @JsonProperty("destinationZIPCode") private String destinationZipCode; - private double weight; - private double length; - private double width; - private double height; - private List mailClasses; + private Double weight; + private Double length; + private Double width; + private Double height; + private List mailClasses; private PriceType priceType; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") private Date mailingDate; + private String destinationCountryCode; private AccountType accountType; private String accountNumber; diff --git a/src/main/java/io/ljunggren/usps/api/model/tracking/TrackingEvent.java b/src/main/java/io/ljunggren/usps/api/model/tracking/TrackingEvent.java index 3fc0b77..fa6d4b6 100644 --- a/src/main/java/io/ljunggren/usps/api/model/tracking/TrackingEvent.java +++ b/src/main/java/io/ljunggren/usps/api/model/tracking/TrackingEvent.java @@ -1,7 +1,5 @@ package io.ljunggren.usps.api.model.tracking; -import java.util.Date; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -13,8 +11,13 @@ @JsonInclude(Include.NON_NULL) public class TrackingEvent { - private String eventCode; - private Date eventTimestamp; - private String eventType; + private String eventCode; + private String eventTimestamp; + private String eventType; + private String eventCity; + private String eventState; + private String eventZIPCode; + private String GMTTimestamp; + private String GMTOffset; -} +} \ No newline at end of file diff --git a/src/main/java/io/ljunggren/usps/api/service/BaseService.java b/src/main/java/io/ljunggren/usps/api/service/BaseService.java index 8f135e5..fae2335 100644 --- a/src/main/java/io/ljunggren/usps/api/service/BaseService.java +++ b/src/main/java/io/ljunggren/usps/api/service/BaseService.java @@ -13,6 +13,9 @@ import org.apache.http.impl.client.HttpClients; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.ljunggren.json.utils.JsonUtils; @@ -41,9 +44,16 @@ return result.toString(); } + public static ObjectMapper getMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); + return mapper; + } + protected T parse(String json, Class clazz) throws Exception { try { - return JsonUtils.jsonToObject(json, clazz); + return JsonUtils.jsonToObject(json, clazz, getMapper()); } catch (JsonProcessingException e) { throw new Exception("Unable to parse response"); } @@ -51,7 +61,7 @@ protected List parseList(String json, Class clazz) throws Exception { try { - return JsonUtils.jsonToList(json, clazz); + return JsonUtils.jsonToList(json, clazz, getMapper()); } catch (JsonProcessingException e) { throw new Exception("Unable to parse response"); } diff --git a/src/test/java/io/ljunggren/usps/api/model/rate/RateResponseTest.java b/src/test/java/io/ljunggren/usps/api/model/rate/RateResponseTest.java new file mode 100644 index 0000000..600bd1e --- /dev/null +++ b/src/test/java/io/ljunggren/usps/api/model/rate/RateResponseTest.java @@ -0,0 +1,29 @@ +package io.ljunggren.usps.api.model.rate; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.ljunggren.json.utils.JsonUtils; +import io.ljunggren.usps.api.service.BaseService; + +public class RateResponseTest { + + private String readFromResources(String file) throws IOException { + return IOUtils.toString(this.getClass().getResourceAsStream(file), "UTF-8"); + } + + @Test + public void deserializeTest() throws IOException { + String json = readFromResources("/io/ljunggren/usps/api/model/tracking/tracking-response.json"); + ObjectMapper mapper = BaseService.getMapper(); + RateResponse rateResponse = JsonUtils.jsonToObject(json, RateResponse.class, mapper); + assertNotNull(rateResponse); + } + +} diff --git a/src/test/java/io/ljunggren/usps/api/model/tracking/TrackingResponseTest.java b/src/test/java/io/ljunggren/usps/api/model/tracking/TrackingResponseTest.java new file mode 100644 index 0000000..7be3ef5 --- /dev/null +++ b/src/test/java/io/ljunggren/usps/api/model/tracking/TrackingResponseTest.java @@ -0,0 +1,29 @@ +package io.ljunggren.usps.api.model.tracking; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.ljunggren.json.utils.JsonUtils; +import io.ljunggren.usps.api.service.BaseService; + +public class TrackingResponseTest { + + private String readFromResources(String file) throws IOException { + return IOUtils.toString(this.getClass().getResourceAsStream(file), "UTF-8"); + } + + @Test + public void deserializeTest() throws IOException { + String json = readFromResources("/io/ljunggren/usps/api/model/tracking/tracking-response.json"); + ObjectMapper mapper = BaseService.getMapper(); + TrackingResponse trackingResponse = JsonUtils.jsonToObject(json, TrackingResponse.class, mapper); + assertNotNull(trackingResponse); + } + +} diff --git a/src/test/resources/io/ljunggren/usps/api/model/rate/rate-response.json b/src/test/resources/io/ljunggren/usps/api/model/rate/rate-response.json new file mode 100644 index 0000000..b1b7768 --- /dev/null +++ b/src/test/resources/io/ljunggren/usps/api/model/rate/rate-response.json @@ -0,0 +1,263 @@ +{ + "rateOptions" : [ { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "PL", + "processingCategory" : "MACHINABLE", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPFB0XXXXR04200", + "price" : 103.6, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International Machinable ISC Large Flat Rate Box" + } ], + "totalBasePrice" : 103.6 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "FP", + "processingCategory" : "MACHINABLE", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPFE2XXXXR04040", + "price" : 48.9, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International Machinable ISC Padded Flat Rate Envelope" + } ], + "totalBasePrice" : 48.9 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_EXPRESS_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "E4", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IEFE0XXXXR04040", + "price" : 78.7, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail Express International ISC Flat Rate Envelope" + } ], + "totalBasePrice" : 78.7 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "FB", + "processingCategory" : "MACHINABLE", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPFB1XXXXR04200", + "price" : 88.15, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International Machinable ISC Medium Flat Rate Box" + } ], + "totalBasePrice" : 88.15 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_EXPRESS_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "15", + "rateIndicator" : "PA", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IEXX0XXXXR15030", + "price" : 93.1, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail Express International ISC Single-piece" + } ], + "totalBasePrice" : 93.1 + }, { + "rates" : [ { + "mailClass" : "FIRST-CLASS_PACKAGE_INTERNATIONAL_SERVICE", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "15", + "rateIndicator" : "SP", + "processingCategory" : "MACHINABLE", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IFXP0XXXXR15400", + "price" : 47.75, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "First-Class Package International Service Machinable ISC Single-piece" + } ], + "totalBasePrice" : 47.75 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "FE", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPFE0XXXXR04040", + "price" : 48.9, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International ISC Flat Rate Envelope" + } ], + "totalBasePrice" : 48.9 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_EXPRESS_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "E6", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IEFE1XXXXR04040", + "price" : 78.7, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail Express International ISC Legal Flat Rate Envelope" + } ], + "totalBasePrice" : 78.7 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "FA", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPFE1XXXXR04040", + "price" : 48.9, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International ISC Legal Flat Rate Envelope" + } ], + "totalBasePrice" : 48.9 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "15", + "rateIndicator" : "SP", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPXX0XXXXR15030", + "price" : 75.4, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International ISC Single-piece" + } ], + "totalBasePrice" : 75.4 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "15", + "rateIndicator" : "SP", + "processingCategory" : "MACHINABLE", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPXX0XXXXR15030", + "price" : 75.4, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International Machinable ISC Single-piece" + } ], + "totalBasePrice" : 75.4 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "FS", + "processingCategory" : "MACHINABLE", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IPFB2XXXXR04040", + "price" : 50.55, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail International Machinable ISC Small Flat Rate Box" + } ], + "totalBasePrice" : 50.55 + }, { + "rates" : [ { + "mailClass" : "PRIORITY_MAIL_EXPRESS_INTERNATIONAL", + "priceType" : "RETAIL", + "dimWeight" : 0, + "zone" : "04", + "rateIndicator" : "FP", + "processingCategory" : "FLATS", + "fees" : [ ], + "startDate" : "2025-10-05", + "endDate" : "", + "productName" : "", + "productDefinition" : "", + "SKU" : "IEFE2XXXXR04040", + "price" : 78.7, + "weight" : 2.49122, + "destinationEntryFacilityType" : "INTERNATIONAL_SERVICE_CENTER", + "description" : "Priority Mail Express International ISC Padded Flat Rate Envelope" + } ], + "totalBasePrice" : 78.7 + } ] +} \ No newline at end of file diff --git a/src/test/resources/io/ljunggren/usps/api/model/tracking/tracking-response.json b/src/test/resources/io/ljunggren/usps/api/model/tracking/tracking-response.json new file mode 100644 index 0000000..444a827 --- /dev/null +++ b/src/test/resources/io/ljunggren/usps/api/model/tracking/tracking-response.json @@ -0,0 +1,33 @@ +{ + "trackingNumber" : "LZ273243180US", + "kahalaIndicator" : false, + "mailClass" : "First-Class Package International Service", + "mailClassCode" : "LC", + "mailingDate" : "2025-12-16", + "mailType" : "IO", + "services" : [ "Small Packets" ], + "serviceTypeCode" : "LZ", + "status" : "Shipping Label Created", + "statusCategory" : "USPS Awaiting Item", + "statusSummary" : "A shipping label has been prepared for your item. A delivery date will be provided when USPS receives the package; contact the shipper or shipping partner with any inquiries.", + "servicesEligibility" : { + "proofOfDeliveryEnabled" : false, + "trackingProofOfDeliveryEnabled" : false, + "RREEnabled" : false + }, + "trackingEvents" : [ { + "eventCity" : "BROWNSBURG", + "eventCode" : "GX", + "eventState" : "IN", + "eventTimestamp" : "2025-12-16T18:39:42-05:00", + "eventType" : "Shipping Label Created", + "eventZIPCode" : "46112", + "GMTTimestamp" : "2025-12-16T23:39:42Z", + "GMTOffset" : "-05:00" + }, { + "eventCode" : "MA", + "eventTimestamp" : "2025-12-16", + "eventType" : "Pre-Shipment Info Sent to USPS" + } ], + "uniqueTrackingID" : "3092b47f-b531-44f2-b45f-ad741969ca13" +} \ No newline at end of file diff --git a/src/test/resources/trackFieldRequest.xml b/src/test/resources/trackFieldRequest.xml deleted file mode 100644 index c1d303a..0000000 --- a/src/test/resources/trackFieldRequest.xml +++ /dev/null @@ -1,6 +0,0 @@ - -1 -127.0.0.1 -tracking - - \ No newline at end of file diff --git a/src/test/resources/trackingResponse.xml b/src/test/resources/trackingResponse.xml deleted file mode 100644 index 0e98d65..0000000 --- a/src/test/resources/trackingResponse.xml +++ /dev/null @@ -1,243 +0,0 @@ - - - USPS Ground Advantage<SUP>&#153;</SUP> - FC - AVON - IN - 46123 - true - false - DM - 2024-09-11 14:25:20.000000 - 444855581 - DANVILLE - IN - 46122 - true - false - false - false - false - Signature Confirmation<SUP>&#153;</SUP> - Up to $100 insurance included - 021 - Delivered, Individual Picked Up at Post Office - Delivered - Your item was picked up at the post office at 1:52 pm on September 18, 2024 in DANVILLE, IN 46122. The item was signed for by A LJUMGGREN. - T - - 1:52 pm - September 18, 2024 - Delivered, Individual Picked Up at Post Office - DANVILLE - IN - 46122 - - - A LJUMGGREN - false - 01 - - 17:52:00 - -04:00 - - - - September 16, 2024 - Redelivery Scheduled - AVON - IN - 46123 - - - - false - VR - - - - - - 3:35 pm - September 13, 2024 - Notice Left (No Authorized Recipient Available) - AVON - IN - 46123 - - - - false - 56 - - 19:35:35 - -04:00 - - - 7:59 am - September 13, 2024 - Out for Delivery - AVON - IN - 46123 - - - - false - OF - - 11:59:41 - -04:00 - - - 7:48 am - September 13, 2024 - Arrived at Post Office - DANVILLE - IN - 46122 - - - - false - 07 - - 11:48:41 - -04:00 - - - 4:35 am - September 13, 2024 - Arrived at USPS Facility - DANVILLE - IN - 46122 - - - - false - U1 - - 08:35:05 - -04:00 - - - 3:21 am - September 13, 2024 - In Transit to Next Facility - - - - - - - false - TL - - 07:21:46 - -04:00 - - - 3:03 am - September 13, 2024 - Departed USPS Regional Facility - INDIANAPOLIS IN DISTRIBUTION CENTER - - - - - - false - T1 - - 07:03:22 - -04:00 - - - 8:27 pm - September 12, 2024 - Arrived at USPS Regional Destination Facility - INDIANAPOLIS IN DISTRIBUTION CENTER - - - - - - false - 10 - - 00:27:19 - -04:00 - - - 10:05 pm - September 11, 2024 - Arrived at USPS Origin Facility - SAINT PAUL - MN - 55131 - - - - false - 10 - - 04:05:21 - -06:00 - - - 8:50 pm - September 11, 2024 - Accepted at USPS Origin Facility - SAINT PAUL - MN - 55128 - - - - false - OA - - 01:50:21 - -05:00 - - - 3:31 pm - September 11, 2024 - Shipment Received, Package Acceptance Pending - SAINT PAUL - MN - 55128 - - - - false - TM - - 20:31:46 - -05:00 - - - 1:48 pm - September 11, 2024 - Shipping Label Created, USPS Awaiting Item - SAINT PAUL - MN - 55128 - - - - false - GX - - 18:48:22 - -05:00 - - - - - -2147219283 - A status update is not yet available on your package. It will be available when the shipper provides an update or the package is given to USPS. Check back soon. Sign up for Informed Delivery<SUP>&reg;</SUP> to receive notifications for packages addressed to you. - - - \ No newline at end of file