Skip to content

Commit

Permalink
Merge pull request #26 from online-photo-submission/sqs-fix-for-HB-ex…
Browse files Browse the repository at this point in the history
…plainability

Got rid of the json slurper in favor of ObjectMapper so deserializati…
  • Loading branch information
slackboxster authored Dec 11, 2024
2 parents 8a8a994 + d83b028 commit 30ec2a3
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/main/groovy/com/cloudcard/photoDownloader/Photo.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.cloudcard.photoDownloader

import com.fasterxml.jackson.annotation.*
import groovy.json.JsonSlurper
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import groovy.transform.EqualsAndHashCode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand All @@ -12,7 +13,6 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

import static groovy.json.JsonOutput.prettyPrint
import static groovy.json.JsonOutput.toJson

@EqualsAndHashCode(includes = ["publicKey"])
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -49,7 +49,6 @@ class Photo {
@JsonIgnore
Map<String, Object> additionalProperties = new HashMap<String, Object>()
Boolean manuallyEdited
String dateCreatedString
Date dateCreated
Integer version
Boolean backgroundReplaced
Expand All @@ -62,18 +61,12 @@ class Photo {
}

static Photo fromSqsMessage(Message message) {
Map map = new JsonSlurper().parseText(message.body()) as Map
map.person = new Person(map.person as Map)
map.links = new Links(map.links as Map)
map.dateCreatedString = map.dateCreated
map.dateCreated = parseDate(map.dateCreatedString)
try {
return new Photo(map)
return new ObjectMapper().readValue(message.body(), new TypeReference<Photo>() { }) as Photo
} catch (Exception e) {
log.error("Error deserializing message ${message?.receiptHandle()}")
log.error(e.message)
log.error("message body follows:\n${prettyPrint(message.body())}")
log.error("mapped values follow:\n${prettyPrint(toJson(map))}")
return null
}
}
Expand Down

0 comments on commit 30ec2a3

Please sign in to comment.