AWS Dynamodb交易库抛出错误,而Serrializing请求抛出、错误、AWS、Dynamodb

2023-09-11 12:11:52 作者:僵持

如何解决这一问题?

 无法序列化的要求
com.amazonaws.services.dynamodbv2.transactions.Request$GetItem@24cab5b6
com.fasterxml.jackson.databind.JsonMappingException:冲突的
吸气定义属性空:
com.amazonaws.services.dynamodbv2.model.AttributeValue#getNULL(0
PARAMS)VS
com.amazonaws.services.dynamodbv2.model.AttributeValue#ISNULL(0
PARAMS)(通过引用链:
com.amazonaws.services.dynamodbv2.transactions.GetItem["request"]->com.amazonaws.services.dynamodbv2.model.GetItemRequest["key"])
    在
com.amazonaws.services.dynamodbv2.transactions.Request.serialize(Request.java:407)
〜[班/:NA]
 

解决方案

杰克逊分不清哪个getter是正确的。你可以告诉它忽略了两种方法之一:

 公共接口DynamoAttributeValueHack {
  @JsonIgnore
  公共布尔ISNULL();

  @JsonIgnore
  公共布尔isBOOl(); //你可能需要这个问题,以及根据您的AWS库版本。
}

myMapper.addMixInAnnotations(AttributeValue.class,DynamoAttributeValueHack.class)
 

AWS DynamoDB 服务

How to fix this?

Failed to serialize request
com.amazonaws.services.dynamodbv2.transactions.Request$GetItem@24cab5b6
com.fasterxml.jackson.databind.JsonMappingException: Conflicting
getter definitions for property "null":
com.amazonaws.services.dynamodbv2.model.AttributeValue#getNULL(0
params) vs
com.amazonaws.services.dynamodbv2.model.AttributeValue#isNULL(0
params) (through reference chain:
com.amazonaws.services.dynamodbv2.transactions.GetItem["request"]->com.amazonaws.services.dynamodbv2.model.GetItemRequest["key"])
    at
com.amazonaws.services.dynamodbv2.transactions.Request.serialize(Request.java:407)
~[classes/:na]

解决方案

Jackson can't tell which getter is the "right" one. You can tell it to ignore one of the two methods:

public interface DynamoAttributeValueHack {
  @JsonIgnore
  public boolean isNull();

  @JsonIgnore
  public boolean isBOOl(); // You may need this as well depending on your AWS library version.
}

myMapper.addMixInAnnotations(AttributeValue.class, DynamoAttributeValueHack.class)