2017-09-28 8 views
0

J'utilise le proxy de service AWS pour exposer DynamoDB en tant qu'API. Pour PutItem cela fonctionne bien, mais je ne sais pas comment mettre à jour un tableau de l'objet. Ci-dessous "paymentDetail" est la liste de la carte, je peux poster à DynamoDB, mais j'ai échoué pour mettre à jour la charge utile JSON. Je ne sais pas ce DynamoDB soutenir ou non, je suis toujours ce message:dynamodb UpdateItem json payload

{ "__type": "com.amazon.coral.service # SerializationException"}

Quelqu'un peut-il partager vos idées comment utiliser le modèle de mappage pour mettre à jour la charge utile JSON? Merci d'avance.

Voici mon code, s'il vous plaît conseiller et aider. S'il vous plaît veuillez me le faire savoir au cas où l'information n'est pas suffisante.

--------- Demande Méthode de UpdateItem ------------

{ 
    "TableName": "claim", 
    "Key": { 
     "claimNumber": { 
      "S": "$input.params("claimNumber")" 
     } 
    }, 
    "UpdateExpression": "set claimStatus = :claimStatus, statusUpdateDate = :statusUpdateDate, netClaimAmount = :netClaimAmount, paymentDetail = :paymentDetail, updatedAt = :updatedAt", 
    "ConditionExpression": "claimNumber = :claimNumber", 
    "ExpressionAttributeValues": { 
     ":claimNumber": {"S": "$input.params("claimNumber")"}, 
     ":claimStatus": {"S": "$input.path("$.claimStatus")"}, 
     ":statusUpdateDate": {"S": "$input.path("$.statusUpdateDate")"}, 
     ":netClaimAmount": {"N": "$input.path("$.netClaimAmount")"}, 
     ":paymentDetail": {"L": "$input.path("$.paymentDetail")"}, 
     ":updatedAt": {"S": "$input.path("$.updatedAt")"} 
}, 
"ReturnValues": "UPDATED_NEW" 

}

------ ---- données de test pour UpdateItem ---------

{ 
    "claimNumber": "000-00-000959", 
    "updatedAt":"2017-09-10", 
    "claimStatus": "close", 
    "statusUpdateDate": "2017-09-13", 
    "netClaimAmount": 60000000, 
    "paymentDetail": [ 
     { 
      "coverage": "AAA", 
      "claimPaymentDate": "2017-09-03", 
      "claimAmount": "10000000", 
      "costCategory": "1", 
      "costType": "A" 
     }, 
     { 
      "coverage": "BBB", 
      "claimPaymentDate": "2017-09-03", 
      "claimAmount": "20000000", 
      "costCategory": "2", 
      "costType": "B" 
     }, 
     { 
      "coverage": "CCC", 
      "claimPaymentDate": "2017-09-03", 
      "claimAmount": "30000000", 
      "costCategory": "3", 
      "costType": "C" 
     } 
    ] 
} 

--- PutItem pour votre information ---

#set($inputRoot = $input.path('$')) 
{ 
    "TableName": "claim", 
    "Item": { 
     "claimNumber": { 
      "S": "$input.path("$.claimNumber")" 
     }, 
     "policyNumber": { 
      "S": "$input.path("$.policyNumber")" 
     }, 
     "productName": { 
      "S": "$input.path("$.productName")" 
     }, 
     "lossDate": { 
      "S": "$input.path("$.lossDate")" 
     }, 
     "lossTime": { 
      "S": "$input.path("$.lossTime")" 
     }, 
     "reportedDate": { 
      "S": "$input.path("$.reportedDate")" 
     }, 
     "lossCause": { 
      "S": "$input.path("$.lossCause")" 
     }, 
     "description": { 
      "S": "$input.path("$.description")" 
     }, 
     "prefectureCode": { 
      "S": "$input.path("$.prefectureCode")" 
     }, 
     "city": { 
      "S": "$input.path("$.city")" 
     }, 
     "address": { 
      "S": "$input.path("$.address")" 
     }, 
     "reportedByType": { 
      "S": "$input.path("$.reportedByType")" 
     }, 
     "createdAt": { 
      "S": "$input.path("$.createdAt")" 
     }, 
     "updatedAt": { 
      "S": "$input.path("$.updatedAt")" 
     }, 
     "claimImageId": { 
      "S": "$input.path("$.claimImageId")" 
     }, 
     "contact": { 
      "M": { 
       "lastName": { 
        "S": "$input.path("$.contact.lastName")" 
       }, 
       "firstName": { 
        "S": "$input.path("$.contact.firstName")" 
       }, 
       "postCode": { 
        "S": "$input.path("$.contact.postCode")" 
       }, 
       "prefectureCode": { 
        "S": "$input.path("$.contact.prefectureCode")" 
       }, 
       "city": { 
        "S": "$input.path("$.contact.city")" 
       }, 
       "address": { 
        "S": "$input.path("$.contact.address")" 
       }, 
       "homePhone": { 
        "S": "$input.path("$.contact.homePhone")" 
       }, 
       "email": { 
        "S": "$input.path("$.contact.email")" 
       } 
      } 
     }, 
     "claimStatus": { 
      "S": "$input.path("$.claimStatus")" 
     }, 
     "statusUpdateDate": { 
      "S": "$input.path("$.statusUpdateDate")" 
     }, 
     "netClaimAmount": { 
      "N": "$input.path("$.netClaimAmount")" 
     }, 
     "paymentDetail": { 
      "L":[ 
       #foreach($elem in $inputRoot.paymentDetail){ 
         "M": { 
          "coverage": { 
           "S": "$elem.coverage" 
          }, 
          "claimPaymentDate": { 
           "S": "$elem.claimPaymentDate" 
          }, 
          "claimAmount": { 
           "S": "$elem.claimAmount" 
          }, 
          "costCategory": { 
           "S": "$elem.costCategory" 
          }, 
          "costType": { 
           "S": "$elem.costType" 
          } 
         } 
       }#if($foreach.hasNext),#end 
       #end 
      ] 
     } 
    } 
} 

Répondre

1

Votre modèle de cartographie du corps semble avoir des problèmes. Veuillez voir ci-dessous le corrigé.

#set($inputRoot = $input.path('$')) 
{ 
    "TableName": "claim", 
    "Key": { 
     "claimNumber": { 
      "S": "$input.path("$.claimNumber")" 
     } 
    }, 
    "UpdateExpression": "set claimStatus = :claimStatus, statusUpdateDate = :statusUpdateDate, netClaimAmount = :netClaimAmount, paymentDetail = :paymentDetail, updatedAt = :updatedAt", 
    "ConditionExpression": "claimNumber = :claimNumber", 
    "ExpressionAttributeValues": { 
     ":claimNumber": {"S": "$input.path("$.claimNumber")"}, 
     ":claimStatus": {"S": "$input.path("$.claimStatus")"}, 
     ":statusUpdateDate": {"S": "$input.path("$.statusUpdateDate")"}, 
     ":netClaimAmount": {"N": "$input.path("$.netClaimAmount")"}, 
       ":updatedAt": {"S": "$input.path("$.updatedAt")"}, 
     ":paymentDetail": { 
      "L":[ 
       #foreach($elem in $inputRoot.paymentDetail){ 
         "M": { 
          "coverage": { 
           "S": "$elem.coverage" 
          }, 
          "claimPaymentDate": { 
           "S": "$elem.claimPaymentDate" 
          }, 
          "claimAmount": { 
           "S": "$elem.claimAmount" 
          }, 
          "costCategory": { 
           "S": "$elem.costCategory" 
          }, 
          "costType": { 
           "S": "$elem.costType" 
          } 
         } 
       }#if($foreach.hasNext),#end 
       #end 
      ] 
     } 
    }, 
"ReturnValues": "UPDATED_NEW" 
}