Class FieldPathPayloadSubsectionExtractor
java.lang.Object
org.springframework.restdocs.payload.FieldPathPayloadSubsectionExtractor
- All Implemented Interfaces:
PayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>
public class FieldPathPayloadSubsectionExtractor
extends Object
implements PayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>
A
PayloadSubsectionExtractor
that extracts the subsection of the JSON payload
identified by a field path.- Since:
- 1.2.0
- Author:
- Andy Wilkinson
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
FieldPathPayloadSubsectionExtractor
(String fieldPath) Creates a newFieldPathPayloadSubsectionExtractor
that will extract the subsection of the JSON payload beneath the givenfieldPath
.protected
FieldPathPayloadSubsectionExtractor
(String fieldPath, String subsectionId) Creates a newFieldPathPayloadSubsectionExtractor
that will extract the subsection of the JSON payload beneath the givenfieldPath
and that will use the givensubsectionId
to identify the subsection. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
extractSubsection
(byte[] payload, org.springframework.http.MediaType contentType) Extracts a subsection of the givenpayload
that has the givencontentType
.byte[]
extractSubsection
(byte[] payload, org.springframework.http.MediaType contentType, List<FieldDescriptor> descriptors) Extracts a subsection of the givenpayload
that has the givencontentType
and that is described by the givendescriptors
.protected String
Returns the path of the field that will be extracted.Returns an identifier for the subsection that this extractor will extract.withSubsectionId
(String subsectionId) Returns an extractor with the givensubsectionId
.
-
Constructor Details
-
FieldPathPayloadSubsectionExtractor
Creates a newFieldPathPayloadSubsectionExtractor
that will extract the subsection of the JSON payload beneath the givenfieldPath
. ThefieldPath
prefixed withbeneath-
with be used as the subsection ID.- Parameters:
fieldPath
- the path of the field
-
FieldPathPayloadSubsectionExtractor
Creates a newFieldPathPayloadSubsectionExtractor
that will extract the subsection of the JSON payload beneath the givenfieldPath
and that will use the givensubsectionId
to identify the subsection.- Parameters:
fieldPath
- the path of the fieldsubsectionId
- the ID of the subsection
-
-
Method Details
-
extractSubsection
public byte[] extractSubsection(byte[] payload, org.springframework.http.MediaType contentType) Description copied from interface:PayloadSubsectionExtractor
Extracts a subsection of the givenpayload
that has the givencontentType
.- Specified by:
extractSubsection
in interfacePayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>
- Parameters:
payload
- the payloadcontentType
- the content type of the payload- Returns:
- the subsection of the payload
-
extractSubsection
public byte[] extractSubsection(byte[] payload, org.springframework.http.MediaType contentType, List<FieldDescriptor> descriptors) Description copied from interface:PayloadSubsectionExtractor
Extracts a subsection of the givenpayload
that has the givencontentType
and that is described by the givendescriptors
.- Specified by:
extractSubsection
in interfacePayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>
- Parameters:
payload
- the payloadcontentType
- the content type of the payloaddescriptors
- descriptors that describe the payload- Returns:
- the subsection of the payload
-
getSubsectionId
Description copied from interface:PayloadSubsectionExtractor
Returns an identifier for the subsection that this extractor will extract.- Specified by:
getSubsectionId
in interfacePayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>
- Returns:
- the identifier
-
getFieldPath
Returns the path of the field that will be extracted.- Returns:
- the path of the field
-
withSubsectionId
Description copied from interface:PayloadSubsectionExtractor
Returns an extractor with the givensubsectionId
.- Specified by:
withSubsectionId
in interfacePayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>
- Parameters:
subsectionId
- the subsection ID- Returns:
- the customized extractor
-