-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pankaj Agrawal
committed
Nov 1, 2021
1 parent
9f20b10
commit 2f446be
Showing
7 changed files
with
238 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
powertools-sqs/src/main/java/software/amazon/payloadoffloading/PayloadS3Pointer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package software.amazon.payloadoffloading; | ||
|
||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static java.util.Optional.empty; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public class PayloadS3Pointer { | ||
private static final Logger LOG = LoggerFactory.getLogger(PayloadS3Pointer.class); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private String s3BucketName; | ||
private String s3Key; | ||
|
||
static { | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); | ||
objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL); | ||
} | ||
|
||
private PayloadS3Pointer() { | ||
|
||
} | ||
|
||
public String getS3BucketName() { | ||
return this.s3BucketName; | ||
} | ||
|
||
public String getS3Key() { | ||
return this.s3Key; | ||
} | ||
|
||
public static Optional<PayloadS3Pointer> fromJson(String s3PointerJson) { | ||
try { | ||
return ofNullable(objectMapper.readValue(s3PointerJson, PayloadS3Pointer.class)); | ||
} catch (Exception e) { | ||
LOG.error("Failed to read the S3 object pointer from given string.", e); | ||
return empty(); | ||
} | ||
} | ||
|
||
public Optional<String> toJson() { | ||
try { | ||
ObjectWriter objectWriter = objectMapper.writer(); | ||
return ofNullable(objectWriter.writeValueAsString(this)); | ||
|
||
} catch (Exception e) { | ||
LOG.error("Failed to convert S3 object pointer to text.", e); | ||
return empty(); | ||
} | ||
} | ||
} |
Oops, something went wrong.