I'm trying to use a REST resource that accepts a node title and returns a JSON interpretation of a single field. This requires raw HTML that I can then use in DOMDocument. To get the rendered value of a node programmatically with filters applied I tried:
$field_value = $node->get('body')->getValue();
However this doesn't apply any of the filters such as converting newlines/carriage returns into <br/> or striping out unwanted HTML tags. I don't intend to send this to a Twig template so I need the rendered value in a string rather than a render array.
When you use Drupal in a site-building capacity, you use the Manage Display to configure field/layout configuration. What you're actually doing is choosing and configuring plugins to do the formatting for you, information that Drupal then uses to render an entity.
But when you're manually rendering entities or fields of entities, all this work you have to do yourself. When you do ->getValue() or ->value, what you're doing is extracting the raw value from the field, usually a programmatic representation of the value that's stored in the database. Entities also do not carry formatting on their own, that's information stored separate from the entity (e.g. display configuration) - a good example of separation of concerns, entity data vs entity display information.