如何忽略要存储在 DynamoDB 中的 JsonProperty
How to Ignore a JsonProperty to be stored in DynamoDB
这是我使用 DynamodbMapper 存储在 DynamoDB 中的 POJO
@DynamoDBTable(tableName = "Data")
// @JsonIgnoreProperties(value = { "content" })
public class Data {
@DynamoDBRangeKey(attributeName = "Url")
@DynamoDBAutoGeneratedKey
@JsonProperty("url")
private String url;
@DynamoDBHashKey(attributeName = "UserName")
@JsonProperty("userName")
private String userName;
@JsonProperty("title")
@DynamoDBAttribute(attributeName = "Title")
private String pasteTitle;
@JsonProperty("content")
private String content;
@JsonProperty("date")
@DynamoDBAttribute(attributeName = "Date")
private String date;
}
每次我 运行 DynamoDBMapper.save(data)
,即使没有 DynamoDBAttribute
注释,它也会存储 content
。通过使用 @JsonIgnoreProperties(value = { "content" })
它使该值为 null 并且不存储内容。但我想将内容存储在 S3 而不是 DynamoDB 中,因此正在寻找一种在 DynamoDBAttribute 中忽略它的方法。
您可以使用 @DynamoDBIgnore
- AWS documentation
在你的例子中:
@DynamoDBIgnore
public String getContent() {
return content;
}
这是我使用 DynamodbMapper 存储在 DynamoDB 中的 POJO
@DynamoDBTable(tableName = "Data")
// @JsonIgnoreProperties(value = { "content" })
public class Data {
@DynamoDBRangeKey(attributeName = "Url")
@DynamoDBAutoGeneratedKey
@JsonProperty("url")
private String url;
@DynamoDBHashKey(attributeName = "UserName")
@JsonProperty("userName")
private String userName;
@JsonProperty("title")
@DynamoDBAttribute(attributeName = "Title")
private String pasteTitle;
@JsonProperty("content")
private String content;
@JsonProperty("date")
@DynamoDBAttribute(attributeName = "Date")
private String date;
}
每次我 运行 DynamoDBMapper.save(data)
,即使没有 DynamoDBAttribute
注释,它也会存储 content
。通过使用 @JsonIgnoreProperties(value = { "content" })
它使该值为 null 并且不存储内容。但我想将内容存储在 S3 而不是 DynamoDB 中,因此正在寻找一种在 DynamoDBAttribute 中忽略它的方法。
您可以使用 @DynamoDBIgnore
- AWS documentation
在你的例子中:
@DynamoDBIgnore
public String getContent() {
return content;
}