Contact Us 1-800-596-4880

findDataFormatDescriptorByMime

findDataFormatDescriptorByMime(mime: dw::module::Mime::MimeType): DataFormatDescriptor | Null

Returns the DataFormatDescriptor based on the dw::module::Mime::MimeType specified or null if there is no DataFormatDescriptor for the given MimeType.

Experimental: This function is an experimental feature that is subject to change or removal from future versions of DataWeave.

Introduced in DataWeave version 2.7.0.

Parameters

Name Type Description

mimeType

dw::module::Mime::MimeType

The MIME type value to search.

Example

This example searches for a JSON DataFormatDescriptor and an unknown DataFormatDescriptor.

Source

%dw 2.0
import * from dw::Runtime
output application/json

var jsonDF = findDataFormatDescriptorByMime({'type': "*", subtype: "json", parameters: {}})
var unknownDF = findDataFormatDescriptorByMime({'type': "*", subtype: "*", parameters: {}})

fun simplify(df: DataFormatDescriptor | Null) = df  match {
  case d is DataFormatDescriptor -> { name: d.name, defaultMimeType: d.defaultMimeType }
  case is Null -> { name: "unknown", defaultMimeType: "unknown" }
}
---
{
  json: simplify(jsonDF),
  unknown: simplify(unknownDF)
}

Output

{
  "json": {
    "name": "json",
    "defaultMimeType": "application/json"
  },
  "unknown": {
    "name": "unknown",
    "defaultMimeType": "unknown"
  }
}