# How to specify defaults for nested modelmap?

**URL:** <https://discuss.gradle.org/t/how-to-specify-defaults-for-nested-modelmap/23559>\
**Category:** Help/Discuss\
**Created:** [August 2, 2017, 5:23pm UTC](https://discuss.gradle.org/t/how-to-specify-defaults-for-nested-modelmap/23559 "2017-08-02T17:23:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jrm/32/7022_2.png) [@jrm](https://discuss.gradle.org/u/jrm)\
**Post date:** [August 2, 2017, 5:23pm UTC](https://discuss.gradle.org/t/how-to-specify-defaults-for-nested-modelmap/23559/1 "2017-08-02T17:23:09Z")

</div>

I am reasonably new to Gradle in general, and very new to the managed class and Rules/RuleSource aspect in particular. I have been experimenting a fair bit to learn more, but have run into a scenario similar to the following:

```
@Managed
interface Inner {
    String getString()
    void setString( String string )
}
@Managed
interface Outer {
    ModelMap<Inner> getInners()
}
class MyRules extends RuleSource {
    @Model
    void outers(ModelMap<Outer> outers) {}
    
    @Defaults
    void defaultInnerString(ModelMap<Outer> outers) {
        // ???
    }
}
apply plugin: MyRules  

```

The goal is to create a default _Inner_ if one has not been explicitly configured in the build configuration file. The issue I’m running into is, any attempt to determine whether or not _Inner_ has been defined is met with the following exception:

```
Build file '/Users/jmash/scratch/build.gradle' line: 18

* What went wrong:
Execution failed for task ':model'.
> Exception thrown while executing model rule: MyRules#defaultInners(ModelMap<Outer>)
   > Attempt to read from a write only view of model element 'outers' of type 'ModelMap<Outer>' given to rule MyRules#defaultInners(ModelMap<Outer>)

```

This feels like I am overlooking something simple somewhere, but I’ve been through a lot of documentation and Gradle source to try and understand how to achieve this goal, and keep turning up empty.

Is this possible, and if so, how would I go about achieving this?
