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
ConstructorsModifierConstructorDescriptionprotectedFieldPathPayloadSubsectionExtractor(String fieldPath) Creates a newFieldPathPayloadSubsectionExtractorthat will extract the subsection of the JSON payload beneath the givenfieldPath.protectedFieldPathPayloadSubsectionExtractor(String fieldPath, String subsectionId) Creates a newFieldPathPayloadSubsectionExtractorthat will extract the subsection of the JSON payload beneath the givenfieldPathand that will use the givensubsectionIdto identify the subsection. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]extractSubsection(byte[] payload, @Nullable org.springframework.http.MediaType contentType) Extracts a subsection of the givenpayloadthat has the givencontentType.byte[]extractSubsection(byte[] payload, @Nullable org.springframework.http.MediaType contentType, List<FieldDescriptor> descriptors) Extracts a subsection of the givenpayloadthat has the givencontentTypeand that is described by the givendescriptors.protected StringReturns 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 newFieldPathPayloadSubsectionExtractorthat will extract the subsection of the JSON payload beneath the givenfieldPath. ThefieldPathprefixed withbeneath-with be used as the subsection ID.- Parameters:
fieldPath- the path of the field
-
FieldPathPayloadSubsectionExtractor
Creates a newFieldPathPayloadSubsectionExtractorthat will extract the subsection of the JSON payload beneath the givenfieldPathand that will use the givensubsectionIdto identify the subsection.- Parameters:
fieldPath- the path of the fieldsubsectionId- the ID of the subsection
-
-
Method Details
-
extractSubsection
public byte[] extractSubsection(byte[] payload, @Nullable org.springframework.http.MediaType contentType) Description copied from interface:PayloadSubsectionExtractorExtracts a subsection of the givenpayloadthat has the givencontentType.- Specified by:
extractSubsectionin interfacePayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>- Parameters:
payload- the payloadcontentType- the content type of the payload- Returns:
- the subsection of the payload
-
extractSubsection
public byte[] extractSubsection(byte[] payload, @Nullable org.springframework.http.MediaType contentType, List<FieldDescriptor> descriptors) Description copied from interface:PayloadSubsectionExtractorExtracts a subsection of the givenpayloadthat has the givencontentTypeand that is described by the givendescriptors.- Specified by:
extractSubsectionin 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:PayloadSubsectionExtractorReturns an identifier for the subsection that this extractor will extract.- Specified by:
getSubsectionIdin 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:PayloadSubsectionExtractorReturns an extractor with the givensubsectionId.- Specified by:
withSubsectionIdin interfacePayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor>- Parameters:
subsectionId- the subsection ID- Returns:
- the customized extractor
-