我无法找到此格式的名称,因此想出如何将其转换为POJO
{
ExampleKey1: ExampleValue1,
ExampleKey2: ExampleValue2,
ExampleObjectKey: {
"ObjectKey" : "ObjectValue"
}
}
这显然不是JSON或ION。有什么建议吗?
一点背景知识:
我正在尝试使用JMS异步读取SQS消息(通过SNS发布),如下所示:https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/getting-started.html - 转到"异步接收消息"
我收到的信息是这样的:
{MessageId: 123-123-123,ReceiptHandle: BigTextWithCharactersLike+and/andNumbers123,MD5OfBody: AlphaNumberic123,Body: {
"Type" : "Notification",
"MessageId" : "uuid-uuid-uuid-uuid",
"TopicArn" : "arn:aws:sns:us-west-2:someARN",
"Message" : "{\"this\":\"is\",\"the\":\"part\",\"i\":\"am\",\"interested\":\"in\"}",
"Timestamp" : "timestamp",
"SignatureVersion" : "1",
"Signature" : "alphanumeric+charatersLike+and/and==",
"SigningCertURL" : "https://an-sns-url",
"UnsubscribeURL" : "https://an-sns-url"
},Attributes: {},MessageAttributes: {}}
通过在消息上执行以下操作我发现:
public void onMessage(Message message) {
try {
// Cast the received message as TextMessage and print the text to screen.
System.out.println("Received: " + ((TextMessage) message).getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
我已用上面的虚拟值替换了实际值。如果我可以将上述内容解析为POJO,我将能够提取" Body"因此"消息"这是我感兴趣的部分。
PS:注意文本基本上是POJO https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sqs/model/Message.html