The method toJSONPretty() is undefined for the type Map<String,AttributeValue>

0

Hello I've a jsp with code (from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ScanJavaDocumentAPI.html) :

...

<%@ page import="com.amazonaws.services.dynamodbv2.AmazonDynamoDB" %>
<%@ page import="com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.DynamoDB" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.Item" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.ItemCollection" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.ScanOutcome" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.Table" %>
<%@ page import="com.amazonaws.services.dynamodbv2.model.AttributeValue" %>
<%@ page import="com.amazonaws.services.dynamodbv2.model.ScanRequest" %>
<%@ page import="com.amazonaws.services.dynamodbv2.model.ScanResult" %>


...

<%

AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
        DynamoDB dynamoDB = new DynamoDB(client);
        String tableName = "TicketsWalletUsersDev";

        // Table table = dynamoDB.getTable(tableName);

        
        Map<String, AttributeValue> lastKeyEvaluated = null;
        do {
            ScanRequest scanRequest = new ScanRequest()
                .withTableName(tableName)
                .withLimit(10)
                .withExclusiveStartKey(lastKeyEvaluated);

            ScanResult result = client.scan(scanRequest);
            for (Map<String, AttributeValue> item : result.getItems()){                              
                System.out.println(item.toJSONPretty());
            }
            lastKeyEvaluated = result.getLastEvaluatedKey();
        } while (lastKeyEvaluated != null);

%>

It gives the error:

The method toJSONPretty() is undefined for the type Map<String,AttributeValue>

I want the string containing the true json and not the string returned from item.toString() that is :

{addresses={M: {mobile+75@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1583142338893,}, verified={BOOL: true}},}, federico+11@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581332986414,}, verified={BOOL: true}},}, federico+signup3@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581330211793,}, verified={BOOL: true}},}, federico+33@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581330013122,}, verified={BOOL: true}},}, mobile@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1583162677615,}, verified={BOOL: true}},}, federico+12@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581333042026,}, verified={BOOL: true}},}, federico+2@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581332941950,}, verified={BOOL: true}},}},}, created={S: 2020-02-05T10:40:17.887Z,}, userName={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6,}}

Thanks!

gefragt vor 2 Jahren528 Aufrufe
1 Antwort
0
Akzeptierte Antwort

There is no toJsonPretty() for Map<String, AttributeValue> in your code.

To get json, you should get Item first from the table. You can refer the code example below Specifying Optional Parameters part here https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPIItemCRUD.html#JavaDocumentAPIGetItem

SUPPORT-TECHNIKER
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen