2

I'm having

.transform(Transformers.fromJson(SNSMessage.class))

not return a value transformed from my JSON. The JSON input is

{
    "Type": "Notification",
    "MessageId": "b5c64f3f-59e3-5fce-9ad6-1e98973c9537",
    "TopicArn": "arn:aws:sns:us-east-1:194477963434:local-hera-update",
    "Subject": "com.accuity.hera.model.HeraNotification",
    "Message": "{\"id\":\"65e60559-cab5-4027-88a2-46185fbd50b9\",\"resourceType\":\"listItem\",\"action\":\"I\",\"timeOfAction\":\"2017-05-30T19:48:46Z\",\"source\":\"gwl\"}",
    "Timestamp": "2017-05-30T19:48:47.593Z",
    "SignatureVersion": "1",
    "Signature": "Xz0qg0byLMA1fwIRbi7aWcEzhtcLBOmzyUluL1W5URu4WaiEO3G\/+hPSpsFXGxcSYNYRgpKhL9QAP2qLkuMlSEMqiEOHaSr88UaB8QRV2lUEjdBAWpuFYVBPdb+jpo6n3m89vVHoYfFWk8yBkc0zuoRl4OYcUXfTZiWWQkkrT8r9OzWU8LxQwgf0jgr1xEoqbl7uMHIp7nHp3cKstQ0mbK6yxMQ8faxfDm+IwH3k8BBH2\/CXmRg9WME6JK77jvagMUHNhUahWKIjm4iz+TCQCdnmHQR21hmgxlkhdrSxZ1FBbk6BjxfX7gorEwwfY1gYNoZCXxsN63+4vSiFMlOAAQ==",
    "SigningCertURL": "https:\/\/sns.us-east-1.amazonaws.com\/SimpleNotificationService-b95095beb82e8f6a046b3aafc7f4149a.pem",
    "UnsubscribeURL": "https:\/\/sns.us-east-1.amazonaws.com\/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:194477963434:local-hera-update:7de3da56-9e6c-43ca-9abc-d46fff379380"
}

and the class definition is:

public class SNSMessage {
    private String Type;
    private String MessageId;
    private String TopicArn;
    private String Subject;
    private String Message;
    private String Timestamp;
    private String SignatureVersion;
    private String Signature;
    private String SigningCertURL;
    private String UnsubscribeURL;
}

any ideas why the SNSMessage is coming back with all its fields set to null?

12
  • Can't you use jackson's ObjectMapper? Commented May 31, 2017 at 19:25
  • Possible duplicate of stackoverflow.com/questions/26257622/… Commented May 31, 2017 at 19:26
  • Federico Piazza--jackson's ObjectMapper is the underlying implementation, Commented May 31, 2017 at 19:30
  • Ivan Pronin--there's no traceback happening and it's not a question of complicated structures as in the question you referenced. Commented May 31, 2017 at 19:31
  • @DonHosek, then can't you do ObjectMapper mapper = new ObjectMapper(); mapper.readValue(json, SNSMessage .class); ? Commented May 31, 2017 at 19:40

1 Answer 1

1

The problem you have is that your json attributes are using a different capitalization than your pojo properties.

It means you have Type as json attribute and type detected for your getter.

You need to use @JsonProperty annotation like this:

@JsonProperty("Type") 
private String type;
...
// getters / setters for type

Btw, if you don't want to follow the java naming standard and have Type as well as the pojo property, then just add the @JsonProperty to the property with no args

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.