Smile factory runtime exception

10 views
Skip to first unread message

Guido Medina

unread,
Nov 14, 2019, 5:20:40 AM11/14/19
to jackson-user
Hi all, how can I prevent this from happening?

Caused by: com.fasterxml.jackson.core.JsonGenerationException: Broken surrogate pair: first char 0xD83C, second 0x002E; illegal combination
at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:2080)
at com.fasterxml.jackson.dataformat.smile.SmileGenerator._convertSurrogate(SmileGenerator.java:2146)
at com.fasterxml.jackson.dataformat.smile.SmileGenerator._shortUTF8Encode2(SmileGenerator.java:1985)
at com.fasterxml.jackson.dataformat.smile.SmileGenerator._shortUTF8Encode(SmileGenerator.java:1944)
at com.fasterxml.jackson.dataformat.smile.SmileGenerator._writeNonSharedString(SmileGenerator.java:1039)
at com.fasterxml.jackson.dataformat.smile.SmileGenerator.writeString(SmileGenerator.java:962)
at com.fasterxml.jackson.databind.ser.std.StringSerializer.serialize(StringSerializer.java:41)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:722)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:722)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:4094)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:3428)

Many thanks,
Guido.

Tatu Saloranta

unread,
Nov 15, 2019, 1:43:47 PM11/15/19
to jackson-user
On Thu, Nov 14, 2019 at 2:20 AM Guido Medina <oxy...@gmail.com> wrote:
>
> Hi all, how can I prevent this from happening?
>
> Caused by: com.fasterxml.jackson.core.JsonGenerationException: Broken surrogate pair: first char 0xD83C, second 0x002E; illegal combination
> at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:2080)
> at =

This means that you are trying to encode a Java String with invalid
contents: one that contains UCS-2 character that is invalid for
Unicode content. Unicode code points beyond 16-bit range are encoded
in UCS-2 (which is how Java Strings are internally represent) by 2
`char`s, but only a subset of values are valid.

If you are not familiar with "surrogate pairs", you can see f.ex here:
https://stackoverflow.com/questions/5903008/what-is-a-surrogate-pair-in-java
for more explanation

The problem for encoder, specifically, is that these `char`s are not
legal to encode separately for UTF-8. So although JDK does not prevent
their use (they are sort of bolt-on to original Java/JDK approach...
somewhere between Unicode 1 and 2 addition I think), they are not
valid for other Unicode encodings such as UTF-8.

To add insult to injury, JSON spec actually DOES allow encoding these
using backlash escapes... but that is not available with binary
encodings (and TBH really really should not be allowed in JSON either
but here we are).

So the fix is to figure out what exactly is producing this invalid content.

-+ Tatu +-

Guido Medina

unread,
Nov 15, 2019, 1:50:05 PM11/15/19
to jackso...@googlegroups.com
Thank you a lot Tatu, that really explains; specially in the application that happened which deal with many time zones and locales.

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10gwzTtZkE6fUNyHfsNXD1KNipkktjW5q4fgo-3WySzOig%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages