---
schema_version: "1"
id: 641c149c2e3f64371f48371387102bd7fb8f8632ae64715b13858b0b299d54f2
title: Choice ルーターの移行
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.8/migration-core-choice.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.8/migration-core-choice
source_site: docs.mulesoft.com
content_type: documentation
content_hash: a3b95075cfb1720874687789229a4b3ff530c1c8f63ae4f2fe1081c8b0bdd119
description: MuleSoft Documentation Site
release: "4.8"
latest: false
---
# Choice ルーターの移行

次を除き、Mule 3 と Mule 4 の Choice ルーターはほとんど変更されていません。

- DataWeave が式言語となり、when ステートメントで MEL の代わりに実際に使用されます。
- `<otherwise>`​ ブロックは省略可能になりました。

## [](#when-ブロックの式言語)when ブロックの式言語

when 式は MEL から DataWeave に変更する必要があります。これは、あらゆる形式を解釈する DataWeave の機能を利用し、必要のない変換を回避できることを意味します。たとえば、ユーザーを表す JSON ドキュメントが HTTP 経由で投稿されるフローがあり、そのユーザーが未成年かどうかを確認する必要があるとします。

Mule 3 の例: MEL

```xml
<flow name="checkAge">
  <http:listener path="person" method="POST" config-ref="http" />
  <json:json-to-object-transformer />
  <choice>
    <when expression="#[payload.age > 21]">
      <logger message="adult" />
    </when>
    <otherwise>
      <logger message="underage" />
    </otherwise>
  </choice>
</flow>
```

Mule 4 では、形式が JSON か Java かを気にする必要はなく、ただ次を実行します。

Mule 4 の例: DataWeave 2

```xml
<flow name="checkAge">
  <http:listener path="person" method="POST" config-ref="http" />
  <choice>
    <when expression="#[payload.age > 21]">
      <logger message="adult" />
    </when>
    <otherwise>
      <logger message="underage" />
    </otherwise>
  </choice>
</flow>
```

## [](#省略可能な-otherwise)省略可能な otherwise

Mule 3 では ​`<otherwise>`​ ブロックは必須でした。代替ロジックが不要だった場合、​`<otherwise>`​ ブロックに含まれるのは重要ではないロガーになることが多々ありました。Mule 4 では ​`<otherwise>`​ ブロックは省略可能で、必要ない場合は指定する必要がありません。

## [](#関連情報)関連情報

[Mule 4 の概要: エラーハンドラー](https://docs.mulesoft.com/jp/mule-runtime/4.8/intro-error-handlers)

[MEL から DataWeave への移行](https://docs.mulesoft.com/jp/mule-runtime/4.8/migration-mel)

[DataWeave 1.0 から 2.x への移行](https://docs.mulesoft.com/jp/mule-runtime/4.8/migration-dataweave)