> For the complete documentation index, see [llms.txt](https://tech.x2bee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tech.x2bee.com/dev-guide/developer-guide-en/dev-start/interactive-blocks/common-response-value-handling.md).

# Common Response Value Handling

The following explains X2BEE's common Response value handling.

This covers the common handling logic, configuration values, custom annotation usage, and examples.

***

## Common Handling Overview

Common response value handling works as follows.

* String, int, List, Map, Model objects, etc. → Set into the payload of the common Response model → the Response object is included in a ResponseEntity and returned
* Response → the Response object is included in a ResponseEntity and returned
* If it is already a ResponseEntity object, it is returned as is

## Using Configuration Values

To use configuration values, the application.yml file is used.

The setting that commonly wraps response values into the common Response model defaults to true.

If you do not want to use this setting, set the global.response.advice setting to false in the application.yml file.

{% hint style="warning" %}
Even without this configuration value, the default value in the code is true, so to disable common handling you must explicitly set the value below to false in application.yml. Deleting the setting does not disable it.
{% endhint %}

Example (application.yml):

```yaml
global:
  response:
    advice: true
```

## Using Custom Annotations

You can use the two custom annotations below to control the common response handling behavior for a specific controller/handler.

* @EnableResponseBodyAdvice — Forcibly applies common response value handling to the handler
* @DisableResponseBodyAdvice — Disables common response value handling for the handler

{% stepper %}
{% step %}

### Enable Example

Example using @EnableResponseBodyAdvice:

{% code title="SampleController - enable example" %}

```
```

{% endcode %}

```java
public class SampleController {

    @EnableResponseBodyAdvice
    @GetMapping("/search2")
    public ResponseEntity<List<SampleResponse>> searchSamples2(@RequestBody Optional<SampleRequest> sampleRequest) {
        // with data
        log.info("sampleRequest: {}", sampleRequest.isPresent() ? sampleRequest.get() : "");
        List<SampleResponse> data = sampleService.searchSamples();
        return ResponseEntity.ok().body(data);
    }
}
```

Description: When using @EnableResponseBodyAdvice, even if the configuration value is false, common response value handling is applied according to the annotation, and the result is ultimately returned in the Response format.
{% endstep %}

{% step %}

### Disable Example

Example using @DisableResponseBodyAdvice:

{% code title="SampleController - disable example" %}

```
```

{% endcode %}

```java
public class SampleController {

    @DisableResponseBodyAdvice
    @GetMapping("/search3")
    public ResponseEntity<List<SampleResponse>> searchSamples3(@RequestBody Optional<SampleRequest> sampleRequest) {
        // with data
        log.info("sampleRequest: {}", sampleRequest.isPresent() ? sampleRequest.get() : "");
        List<SampleResponse> data = sampleService.searchSamples();
        return ResponseEntity.ok().body(data);
    }
}
```

Description: When using @DisableResponseBodyAdvice, even if the configuration value is absent or true, common response value handling is not applied according to the annotation, and the result is returned in List format.
{% endstep %}
{% endstepper %}
