Last active
September 10, 2015 13:27
-
-
Save warmuuh/67797f5910a64954c7df to your computer and use it in GitHub Desktop.
blogspot-snippets-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/v1") | |
ProfileV1Controller { | |
@RequestMapping("/profile") | |
ProfileV1 getProfile(){ | |
return new ProfileV1(); | |
} | |
} | |
@Controller | |
@RequestMapping("/v2") | |
ProfileV2Controller { | |
@RequestMapping("/profile") | |
ProfileV2 getProfile(){ | |
return new ProfileV2(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
ProfileController { | |
@RequestMapping("/profile") | |
@VersionRange(Version.V1) | |
ProfileV1 getProfileV1(){ | |
return new ProfileV1(); | |
} | |
@RequestMapping("/profile") | |
@VersionRange(Version.V2) | |
ProfileV2 getProfileV2(){ | |
return new ProfileV2(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
ProfileController { | |
@RequestMapping("/profile") | |
@VersionRange(@Version.V1) @JsonView(Views.V1) | |
Profile getProfileV1(){ | |
return getProfileV2(); | |
} | |
@RequestMapping("/profile") | |
@VersionRange(@Version.V2) @JsonView(Views.V2) | |
Profile getProfileV2(){ | |
return new Profile(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ControllerAdvice | |
public class VersionRangeResponseBodyAdvice extends AbstractMappingJacksonResponseBodyAdvice { | |
@Override | |
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) { | |
return (AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType) && returnType.getMethodAnnotation(VersionRange.class) != null); | |
} | |
@Override | |
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, | |
MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) { | |
Version selectedVersion = //retrieve requested version from request object; | |
bodyContainer.setSerializationView(selectedVersion.getDefaultView()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
ProfileController { | |
@RequestMapping("/profile") | |
@VersionRange({@Version.V1, @Version.V2}) | |
Profile getProfile(){ | |
return new Profile(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment