Question: I have this recursive function which is used to generate all possible up and lower cases to any string value you pass it to it.

Here is the code sample and the output:

```
def test (name):

    if not name:
        yield ""

    else:
        first=name[:1]

        for sub in test(name[1:]):

            yield first.lower()+sub
            yield first.upper()+sub
            #print (first)

for x in test("abc"):
    print (x)

```

the output will be like this : 

```
abc
Abc
aBc
ABc
abC
AbC
aBC
ABC

```

and if I add print function under the two yield functions:

```
print(first)

```

the out put will be like this : 

```
abc
Abc
a
aBc
ABc
a
b
abC
AbC
a
aBC
ABC
a
b
c

```

I just want a clear explanation for each step and what is happening and why I got these value each time and how does it work, because recursive and generators together made me lost here.

Answer: 
I've resolved issue by using Jackson's custom annotations `@JsonTypeInfo` and `@JsonSubTypes`:

```
public class AnswerDto<T> {

    private String uuid;

    private AnswerType type;

    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
    @JsonSubTypes({
            @JsonSubTypes.Type(value = Location.class, name = AnswerType.Types.LOCATION),
            @JsonSubTypes.Type(value = JobTitle.class, name = AnswerType.Types.JOB_TITLE)
    })
    private T value;
}

```
My suggestion is to make a separate interface for possible answer values and use [`@JsonTypeInfo`](https://fasterxml.github.io/jackson-annotations/javadoc/2.4/com/fasterxml/jackson/annotation/JsonTypeInfo.html) on it. You can also drop `type` field from `AnswerDto`, `AnswerType` enum, and additional `*AnswerDto` classes becuse jackson will add type info for you. Like this

```
public class AnswerDto<T extends AnswerValue> {
    private String uuid;
    private T value;
}

@JsonTypeInfo(use = Id.CLASS, include = As.PROPERTY)
interface AnswerValue {}

class Location implements AnswerValue { /*..*/ }
class JobTitle implements AnswerValue { /*..*/ }

```

Resulting json will looks like this

```
{
  "uuid": "e82544ac-1cc7-4dbb-bd1d-bdbfe33dee73",
  "answers": [
    {
      "uuid": "e82544ac-1cc7-4dbb-bd1d-bdbfe33dee73",
      "value": {
        "@class": "com.demo.Location",
        "text": "Dublin",
        "placeId": "121"
      }
    },
    {
      "uuid": "e82544ac-1cc7-4dbb-bd1d-bdbfe33dee73",
      "value": {
        "@class": "com.demo.JobTitle",
        "id": "1",
        "name": "Developer"
      }
    }
  ]
}

```

Which will be parsed using

```
AnswersDto answersDto = objectMapper.readValue(json, AnswersDto.class);

```

But this solution applies only in cases when you are a producer of json data and you do not have to think about backward compatibility.

In other cases you'll have to make custom desetializer for `AnswersDto` class.