You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, ChatClient.entity(Class) uses the default BeanOutputConverter to convert the response content into a POJO, assuming the content is JSON. This is a very reasonable and effective default for many types, including primitive wrappers like Boolean or Integer.
However, when String.class is passed, this behavior becomes less intuitive. The converter still expects a valid JSON string, meaning the content must be wrapped in quotes and have escaped characters, rather than simply returning the raw text of the response.
Now, it's absolutely valid for users to call .content() or to use a custom StructuredOutputConverter if they want the raw string. That’s the current, intentional design. But I want to challenge whether this is the most intuitive default behavior for String.class.
In other frameworks, such as RestTemplate.getForObject(url, String.class) or JAX-RS WebTarget client .post().readEntity(String.class), passing String.class signals that the caller wants the raw response body, as-is. Only when a POJO class is passed do these APIs treat the response as JSON and attempt deserialization.
So, in the spirit of the least-surprise principle, should ChatClient.entity(String.class) follow the same approach and return the plain content directly, rather than interpreting it as a JSON string?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently,
ChatClient.entity(Class)
uses the defaultBeanOutputConverter
to convert the response content into a POJO, assuming the content is JSON. This is a very reasonable and effective default for many types, including primitive wrappers likeBoolean
orInteger
.However, when
String.class
is passed, this behavior becomes less intuitive. The converter still expects a valid JSON string, meaning the content must be wrapped in quotes and have escaped characters, rather than simply returning the raw text of the response.Now, it's absolutely valid for users to call
.content()
or to use a customStructuredOutputConverter
if they want the raw string. That’s the current, intentional design. But I want to challenge whether this is the most intuitive default behavior forString.class
.In other frameworks, such as
RestTemplate.getForObject(url, String.class)
or JAX-RSWebTarget
client.post().readEntity(String.class)
, passingString.class
signals that the caller wants the raw response body, as-is. Only when a POJO class is passed do these APIs treat the response as JSON and attempt deserialization.So, in the spirit of the least-surprise principle, should
ChatClient.entity(String.class)
follow the same approach and return the plain content directly, rather than interpreting it as a JSON string?Beta Was this translation helpful? Give feedback.
All reactions