Decision Answer
The answer to one question in a decision response. There is one implementation per question kind and no other implementation can exist, so a Kotlin when or a Java switch over an answer covers every case.
An answer can be read without the question that produced it. It holds the question's name and kind, the public options or levels, and the typed outcome. It never holds the question's instructions or the decision input. An answer read from JSON holds its options or levels as written. The typed lookup on a response compares them with a question.
String route = switch (response.answer("department")) {
case DecisionAnswer.Choice choice
when choice.getOutcome() instanceof ClassificationResult.Selected selected -> selected.getCategoryId();
case DecisionAnswer.Choice choice -> "triage-queue";
case DecisionAnswer.Proposition proposition -> "not a choice";
case DecisionAnswer.Rating rating -> "not a choice";
};In JSON an answer is an object whose kind member names its class. It has the same form inside a response and on its own.
Inheritors
Types
The answer to a choice question. A selected category id is always one of options.
The answer to a proposition question.
The answer to a rating question. Any evidence in the outcome fits levels: a selected level is one of them, a distribution covers exactly them, and a score is at most the index of the last level.