All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.co.caeldev.spring.mvc.ResponseEntityBuilder Maven / Gradle / Ivy

The newest version!
package uk.co.caeldev.spring.mvc;

import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class ResponseEntityBuilder {

    private HttpStatus statusCode;
    private T resource;
    private HttpHeaders headers = new HttpHeaders();

    ResponseEntityBuilder() {
    }

    public static  ResponseEntityBuilder responseEntityBuilder() {
        return new ResponseEntityBuilder<>();
    }

    public ResponseEntityBuilder statusCode(final HttpStatus statusCode) {
        this.statusCode = statusCode;
        return this;
    }

    public ResponseEntityBuilder entity(final T resource) {
        this.resource = resource;
        return this;
    }

    public ResponseEntityBuilder header(final String key, final String value) {
        headers.add(key, value);
        return this;
    }

    public ResponseEntity build() {
        return new ResponseEntity<>(resource, headers, statusCode);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy