2

I'm trying send to other system through RESTCLIENT data that is in the ISO-8859-1 encode but i'm have a error: "com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0xe3".

I would like change the serialization encode to ISO-8859-1 instead UTF-8, is possible?

If i convert to UTF-8 before send, it work, but i dont want this option bacause the database is ISO-8859-1.

I tried set -Dfile.encoding=ISO-8859-1 in JVM, the value is changed but the error persist.

javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0xe3
at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 480] (through reference chain: com.xxxxxxx.xxx.model.scheduler.Scheduler["nmSchedule"])
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:88)
at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:256)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:163)
at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:151)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy124.findByIdSchedule(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.microprofile.client.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:149)
at com.sun.proxy.$Proxy125.findByIdSchedule(Unknown Source)
at com.xxxxxxx.xxx.services.materialization.MaterializationSchedulerService.saveScheduler(MaterializationSchedulerService.java:28)
Emerson
  • 428
  • 5
  • 16

2 Answers2

2

JSON should be encoced in UTF-8, UTF-16 or UTF-32, see https://www.rfc-editor.org/rfc/rfc7159#section-8.1

Jackson automatically detects which UTF variant it should support. As explained in this SO answer, you can override this mechanism by providing a JsonGenerator to the ObjectMapper : Jackson ObjectMapper with UTF-8 encoding?

In Quarkus, you can customize the ObjectMapper via an ObjectMapperCustomizer as described here: https://quarkus.io/guides/rest-json#jackson

That being said, my advise it really to use UTF-8 (or UTF-16/UTF-32 if you need enhanced charsets) as it's standard in web services.

Community
  • 1
  • 1
loicmathieu
  • 5,181
  • 26
  • 31
  • Thank you for your explanation, i didn't know about this information. We have databases with charset UTF-8 and ISO-8859-1 (legacy) but with this information we will research a migration plan. I managed to serialize with JSONB instead Jackson. – Emerson May 20 '20 at 13:50
0

I managed to serialize by changing to JSONB (Eclipse Yasson implementation) and added charset to media type header.

Emerson
  • 428
  • 5
  • 16
  • Setting a header does not change character encoding: the header is just a hint for the client receiving such message. If you really want to send JSON messages encoded in ISO-8859-1, you probably need to do it with a Filter which rewrites the responses from the system default encoding scheme (or the one configured at JVM level) to the desired one, ISO-8859-1. – giulianopz May 19 '22 at 21:13