Class DynamoDbAttributeValueHelper

java.lang.Object
org.evomaster.client.java.controller.dynamodb.DynamoDbAttributeValueHelper

public final class DynamoDbAttributeValueHelper extends Object
Normalizes DynamoDB request and response values into plain Java objects used by the expression parser and heuristic calculator.

DynamoDB SDK versions expose attribute values through similar accessor methods but different concrete classes. This helper calls those accessors through DynamoDbReflectionHelper so the controller does not need a compile-time dependency on a particular AWS SDK. The resulting representation uses maps, lists, sets, strings, numbers, booleans, and binary values that can be inspected without SDK-specific logic.

The class also resolves DynamoDB attribute types and traverses the restricted document-path syntax accepted by DynamoDbConditionExpression.g4 directly over the normalized maps and lists. Direct traversal preserves the original Java values and distinguishes a missing path from a path whose value is explicitly null.

  • Method Details

    • toPlainMap

      public static Map<String,Object> toPlainMap(Object source)
      Converts a map of DynamoDB attribute values into a deterministic map of plain Java values.

      Keys are converted to strings and null keys are omitted because DynamoDB attribute names are strings. Values are recursively normalized with toPlainValue(Object). A LinkedHashMap is used so source iteration order is retained for reproducible heuristic evaluation and tests.

      Parameters:
      source - input object expected to be a map
      Returns:
      normalized map, or an empty map when source is not a map
    • toPlainValue

      public static Object toPlainValue(Object value)
      Converts one DynamoDB attribute value object into the corresponding plain Java value.

      Already-plain maps and collections are recursively normalized first. Other objects are inspected through the accessor names shared by DynamoDB SDK attribute-value implementations. Scalar values are checked before document and set values to match the mutually exclusive DynamoDB attribute model. Unknown objects are returned unchanged so callers can still handle SDK variants or test values that this helper does not recognize.

      Parameters:
      value - attribute value object
      Returns:
      recursively normalized Java value, or the original object when no known DynamoDB attribute shape is available
    • resolveAttributeType

      public static DynamoDbAttributeType resolveAttributeType(Object value)
      Resolves the DynamoDB attribute type represented by a normalized Java runtime value.

      The heuristic calculator uses this mapping to evaluate attribute_type. Sets are classified by a representative element because Java generic element types are erased. Empty and unrecognized sets fall back to DynamoDbAttributeType.LIST, while unsupported scalar objects fall back to DynamoDbAttributeType.STRING; these defaults preserve the existing behavior for values without enough runtime type information.

      Parameters:
      value - runtime value
      Returns:
      DynamoDB attribute type used by type predicates
    • documentPaths

      public static Set<String> documentPaths(Map<String,Object> item)
      Returns every resolvable document path in a normalized DynamoDB item.

      Map fields use dot notation and list elements use bracketed indexes, matching lookupByPath(Map, String). Container paths are included alongside their descendants, while sets are treated as leaves because DynamoDB document paths cannot address set members. Paths retain the deterministic traversal order of the normalized maps and lists.

      Children are pushed onto a LIFO work stack in reverse order to preserve depth-first preorder.

      Parameters:
      item - normalized DynamoDB item
      Returns:
      snapshot of all resolvable document paths, or an empty set when item is null
    • lookupByPath

      public static DynamoDbValueLookup lookupByPath(Map<String,Object> item, String path)
      Resolves a DynamoDB document path against a normalized item without converting it to JSON.

      Supported paths contain dot-separated map fields and zero or more list indexes on each field, for example profile.country, squads[0].captain, or tournaments[0][1]. Direct map/list traversal avoids an additional JSON dependency or tree conversion and preserves the runtime types consumed by the heuristic calculator.

      Lookup fails when the item or path is absent, a field does not exist, an intermediate value has the wrong container type, or a list index is outside the available range. A successfully resolved explicit null is returned as DynamoDbValueLookup(true, null).

      Parameters:
      item - normalized DynamoDB item
      path - document path produced by the DynamoDB expression parser
      Returns:
      result containing both path-presence information and the resolved value