Class JsonIndexAccessor
java.lang.Object
org.springframework.integration.json.JsonIndexAccessor
- All Implemented Interfaces:
IndexAccessor
,TargetedAccessor
A SpEL
IndexAccessor
that knows how to read indexes from JSON arrays, using
Jackson's ArrayNode
API.
Supports indexes supplied as an integer literal — for example, myJsonArray[1]
.
Also supports negative indexes — for example, myJsonArray[-1]
which equates
to myJsonArray[myJsonArray.length - 1]
. Furthermore, null
is returned for
any index that is out of bounds (see ArrayNode.get(int)
for details).
- Since:
- 6.4
- Author:
- Sam Brannen
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canRead
(EvaluationContext context, Object target, Object index) boolean
canWrite
(EvaluationContext context, Object target, Object index) Class<?>[]
read
(EvaluationContext context, Object target, Object index) void
write
(EvaluationContext context, Object target, Object index, Object newValue)
-
Constructor Details
-
JsonIndexAccessor
public JsonIndexAccessor()
-
-
Method Details
-
getSpecificTargetClasses
- Specified by:
getSpecificTargetClasses
in interfaceTargetedAccessor
-
canRead
- Specified by:
canRead
in interfaceIndexAccessor
-
read
public TypedValue read(EvaluationContext context, Object target, Object index) throws AccessException - Specified by:
read
in interfaceIndexAccessor
- Throws:
AccessException
-
canWrite
- Specified by:
canWrite
in interfaceIndexAccessor
-
write
public void write(EvaluationContext context, Object target, Object index, @Nullable Object newValue) - Specified by:
write
in interfaceIndexAccessor
-