Database Reference
In-Depth Information
Sometimes, developers find it difficult to store and retrieve, so the following is the Java
code to store binary attributes in DynamoDB:
//Convert string representation of XML into byte buffers
ByteBuffer bb =
ByteBuffer.wrap("<student><name>Tanmay</name></student>".getBytes());
// Put bookXml attribute key and value into item.
item.put("studentXML", new AttributeValue().withB(bb));
So, once you invoke the put item request, the values get stored, and the DynamoDB con-
sole shows the Base64 encoded value stored in the bookXML attribute, as shown in the
following screenshot:
To get back the actual value stored in the binary attribute, you can write the following
code:
String studentDetails = new String(
item.get("studentXML").getB().array(), "UTF-8");
System.out.println(studentDetails);
This prints the original string back on the console:
<student><name>James Bond</name></student>
Search WWH ::




Custom Search