Main Content

convertLike

Class: matlab.net.http.HeaderField
Package: matlab.net.http

Convert header field value like another header field

Description

example

value = convertLike(fields,other) converts the Value property of each element of fields to a MATLAB® type, using conversion rules of the field other.

For each header field in fields, MATLAB checks the matlab.net.http.field package for a class that supports a name with the same value as the fields.Name property. If the package contains a class for this field, then convert invokes the convert method of that class. To see the classes in the field package, call the matlab.net.http.HeaderField.displaySubclasses method.

If the conversion fails or if no class supports one of the fields.Name properties, then convertLike throws an exception.

This method does not support heterogeneous arrays. All members of fields must be the same class.

Input Arguments

expand all

Header fields, specified as a vector of matlab.net.http.HeaderField objects. All members of fields must be the same class.

Field to use for conversion rules, specified as string, character vector, HeaderField object, or meta.class identifying a HeaderField subclass in the matlab.net.http.field package.

Output Arguments

expand all

Header field values, returned as a vector of MATLAB types. The types returned depend on the value of the specific class convert method.

Examples

expand all

The response variable is a message that has a Created-Date header field. Its value is formatted like an HTTPDateField object, which returns a datetime object.

myField = response.getFields('Created-Date');
date = myField.convertLike(?matlab.net.http.field.HTTPDateField);
Introduced in R2016b