---
schema_version: "1"
id: 41db0dd78ba532936e55406f486d75081779be116603f01dcab7a93011cc7302
title: The Result Object
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-sdk/latest/result-object.md
canonical_url: https://docs.mulesoft.com/mule-sdk/latest/result-object
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 660a923839dffba8afc5631e0068ef45508b93cb29085c90f661d16e2b4522d1
description: MuleSoft Documentation Site
release: "1.13"
latest: true
---
---
product: Mule SDK
version: 1.13
is-latest-version: true
keywords: mule, sdk, result, output, mimeType, attributes, operation, source
---

# The Result Object

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The `Result` object represents the result of a component’s execution. It is used for cases in which
the component not only needs to return a value to be set on the message payload but also will
specify message attributes and/or a mime type.

The class has two generic types, one for the type of the value that goes into the payload and
another for the type of the returned message attributes.

For example, consider an oversimplified `read` operation from the File connector. This operation
sets the payload to an `InputStream` with the file’s content. It also sets the attributes to a
`FileAttributes` object that contains information, such as file name, size, timestamp, permissions,
and so on.

```java
public Result<InputStream, FileAttributes> read(String path) { (1)
  InputStream content = getContent(path);
  FileAttributes attributes = getAttributes(path);

  return Result.<InputStream, FileAttributes>builder() (2)
        .output(content) (3)
        .attributes(attributes) (4)
        .build(); (5)
}
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>The operation returns a <code>Result&lt;InputStream, FileAttributes&gt;</code>. This tells the runtime that the operation returns an <code>InputStream</code> as payload and <code>FileAttributes</code> as attributes.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Once it obtains the result values, it uses <code>Result.builder()</code> to create a new instance. Note that this is strongly typed, so you need to specify the generics when creating the builder.</td></tr><tr><td><i data-value="3"></i><b>3</b></td><td>The <code>output(Object)</code> method in the builder is used to set the payload.</td></tr><tr><td><i data-value="4"></i><b>4</b></td><td>The <code>attributes(Object)</code> is used to set the attributes.</td></tr><tr><td><i data-value="5"></i><b>5</b></td><td>The example calls the <code>build()</code> method and returns the created <code>Result</code>.</td></tr></tbody></table>

## Setting the Mime Type

The `Result` object can be used to set the output `mimeType`. Building on the previous example, the
operation here makes a best guess about the file’s `mimeType` based on its file extension:

```java
public Result<InputStream, FileAttributes> read(String path) {
  InputStream content = getContent(path);
  FileAttributes attributes = getAttributes(path);

  MediaType guessedMediaType = MediaType.ANY;
  if (path.endsWith(".json")) {
    guessedMediaType = MediaType.APPLICATION_JSON;
  } else if (path.endsWith("*.xml")) {
    guessedMediaType = MediaType.APPLICATION_XML;
  } else if (path.endsWith("*.bin")) {
    guessedMediaType = MediaType.BINARY;
  }

  return Result.<InputStream, FileAttributes>builder()
        .output(content)
        .attributes(attributes)
        .mediaType(guessedMediaType)
        .build();
}
```

> [!TIP] In the example above, the `MediaType` class is not the `@MediaType` annotation but Mule
> API’s `org.mule.runtime.api.metadata.MediaType`.

## Void Attributes

For a use case where you want to set the payload and the `mimeType` but do not want to set
attributes, you use the `<Void>` type, for example:

```java
public Result<InputStream, Void> read(String path) {
  InputStream content = getContent(path);

  return Result.<InputStream, Void>builder()
        .output(content)
        .mediaType(bestGuessMediaType(path))
        .build();
}
```
