Encoding in JAX-RS Support

81 views
Skip to first unread message

Stefan Bodewig

unread,
Oct 15, 2014, 12:24:05 AM10/15/14
to halbuil...@googlegroups.com
Hi

JaxRsHalBuilderSupport uses an OutputStreamWriter with no arguments and
thus uses the platform's default encoding when writing the HAL response.

In JaxRsHalBuilderReaderSupport I've explicitly set the encoding to
UTF-8 as I assumed this was the default encoding for
application/json+hal (as it is for application/json AFAIK). Can anybody
confirm this assumption?

For XML we should probably not use Readers/Writers at all and leave it
to the XML decl to specify the encoding, but UTF likely is JDOM's
default.

In theory the MediaType may carry encoding information that we should
honor.

I think we should do two things:

* look into the MediaType to see whether it specifies a charset and try
to translate that to a Java encoding

* use UTF-8 on both sides if there is no charset property in the
MediaType

and as a third point - hope nobody sends XML without specifying a
charset in the MediaType but using something other than UTF-8 in the XML
declaration.

Stefan

Stefan Bodewig

unread,
Oct 15, 2014, 12:32:15 AM10/15/14
to halbuil...@googlegroups.com
On 2014-10-15, Stefan Bodewig wrote:

> In JaxRsHalBuilderReaderSupport I've explicitly set the encoding to
> UTF-8 as I assumed this was the default encoding for
> application/json+hal (as it is for application/json AFAIK). Can anybody
> confirm this assumption?

Glancing over the specs for application/json and application/hal+json
the former explicitly only permits UTF-encodings (and leaves it to the
client to figure out which it is) the later doesn't state anything about
encoding or charsets.

Stefan

Mark Derricutt

unread,
Oct 15, 2014, 12:44:31 AM10/15/14
to halbuil...@googlegroups.com
On 15 Oct 2014, at 17:23, Stefan Bodewig wrote:

> JaxRsHalBuilderSupport uses an OutputStreamWriter with no arguments and
> thus uses the platform's default encoding when writing the HAL response.

This sounds like it could also relate to an older, closed/won't fix issue:

https://github.com/HalBuilder/halbuilder-core/issues/16

The thread here also discusses JAX-RS. I wonder if we just change JaxRsHalBuilderSupport. writeTo() to default/hard-code to UTF-8?

Mark
signature.asc

Stefan Bodewig

unread,
Oct 15, 2014, 5:10:53 AM10/15/14
to halbuil...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages