Spun off of #2574077: REST Export display cannot show any raw output for fields using the Field field handler, dependent on commits from that issue
Problem/Motivation
If you have a view, add a REST Export display, use the Field field handler, and set "raw output" on a reference field (ie File, Image, Content, etc.), it always outputs "null" instead of an actual value.
Basically, this:

Causes this:
{
"title": "Test Page title",
"field_test_image": null,
"field_test_content_reference": null,
"field_test_taxonomy_reference": null
}
Proposed resolution
I think the issue stems from FieldItemBase::__get.
public function __get($name) {
// There is either a property object or a plain value - possibly for a
// not-defined property. If we have a plain value, directly return it.
if (isset($this->properties[$name])) {
return $this->properties[$name]->getValue();
}
elseif (isset($this->values[$name])) {
return $this->values[$name];
}
}
Files have target_id's, not names, so they get to this point and break.
Remaining tasks
Fix it
Tests
User interface changes
API changes
Data model changes
Comments
Comment #2
charginghawk commentedComment #3
charginghawk commentedJust to share my temporary workaround for this issue...
What I'm doing to circumvent this is creating custom Fields format via plugin, ie \Drupal\mymodule\Plugin\views\row\MymoduleDataFieldRow that extends Drupal\rest\Plugin\views\row\DataFieldRow, changing the render function to something like...
Comment #4
wim leersSo, this is when using
\Drupal\rest\Plugin\views\row\DataFieldRow'sraw_outputfield option.Comment #5
vasi commentedI think this is happening due to \Drupal\views\Plugin\views\field\Field::getValue():
Notice that if there is no 'value', such as with reference fields, this doesn't yield anything interesting. Even when 'value' exists, it may not be the only relevant property—eg: formatted text fields, where we might be interested in 'format' or 'summary' as well.
Does anything else ever call this method? The only thing I can find is in StylePluginBase::renderGrouping().
Comment #7
lykyd commentedThis issue is still happening in Drupal 8.1.6
I'm using a Rest view and I'm trying to apply the "Raw Output" option to a Custom text field so it doesn't change my "var&var2" in "var&var2".
The issue also happens when I use any other field like "Content: Path" for example and decide to rewrite its output (Rewrite result -> Override the output).
It gives my NULL instead of printing my a raw rewrited value.
Comment #10
wim leers@damiankloip added the "raw output" capability to
DataFieldRowin #1929014: Fix views rest export plugin render values and add option to output raw values and included test coverage at\Drupal\rest\Tests\Views\StyleSerializerTest::testFieldRawOutput()Comment #18
quietone commentedI tested this on 9.4.x and was not able to reproduce this error. And according to #10 this was fixed in #1929014: Fix views rest export plugin render values and add option to output raw values.
Therefore, closing as outdated
Thanks!
Comment #19
lawxen commentedI found the problem still exist on an site of Drupal9.5.3
Comment #20
lawxen commented