# Can I use an @Managed object as an @Input?

**URL:** <https://discuss.gradle.org/t/can-i-use-an-managed-object-as-an-input/17291>\
**Category:** Help/Discuss\
**Created:** [April 29, 2016, 7:26pm UTC](https://discuss.gradle.org/t/can-i-use-an-managed-object-as-an-input/17291 "2016-04-29T19:26:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Appu\_Goundan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/appu_goundan/32/774_2.png) [@Appu\_Goundan](https://discuss.gradle.org/u/Appu_Goundan)\
**Post date:** [April 29, 2016, 7:26pm UTC](https://discuss.gradle.org/t/can-i-use-an-managed-object-as-an-input/17291/1 "2016-04-29T19:26:49Z")

</div>

I want to use an `@Managed` object as a task `@Input` but the generated Model objects from Gradle don’t seem to be serializable. I have some configuration that have a bunch of parameters and I don’t really want to replicate those configuration in tasks. Given that @Managed objects are pretty restricted in the types they allow, is there a way to get them to be used as task inputs?

This is kind of what I want to do

```gradle
@Managed
public interface X {
  ...
}

public class MyTask extends DefaultTask{
  private X x;

  @Input
  public getX() {
    return x;
  }

  @TaskAction
  ...

```

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [April 30, 2016, 11:52pm UTC](https://discuss.gradle.org/t/can-i-use-an-managed-object-as-an-input/17291/2 "2016-04-30T23:52:57Z")

</div>

You can get the behavior you want by annotating the input with [`@Nested`](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/Nested.html) and placing the appropriate annotations on the properties of the managed type. This is the typical way to handle inputs that are non-serializable complex types and is no different for managed types.

```
@Managed
public interface X {
    @Input 
    String getSomeProperty()
    ...
}

public class MyTask extends DefaultTask{
  private X x;

  @Input
  @Nested
  public getX() {
    return x;
  }

  @TaskAction
  ...
```

---

<div class="post-metadata">

**Author:** ![Appu\_Goundan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/appu_goundan/32/774_2.png) [@Appu\_Goundan](https://discuss.gradle.org/u/Appu_Goundan)\
**Post date:** [May 2, 2016, 6:19pm UTC](https://discuss.gradle.org/t/can-i-use-an-managed-object-as-an-input/17291/3 "2016-05-02T18:19:53Z")

</div>

Oh yeah **`@Nested`** is exactly what I wanted, I have never come across it before in the user guide or anywhere else before. Is it a new feature?

One more thing, it looks like @Input isn’t necessary if @Nested is applied?

```gradle
    @Input //<--- is @Input necessary here?
    @Nested
    public getX() {
     ...

```

The implication is the `@Input` and `@Output` annotations are always defined on the Complex object itself?
