Jackson cannot parse values with hexadecimal digits

596 views
Skip to first unread message

hil...@gmail.com

unread,
Apr 17, 2018, 11:02:10 AM4/17/18
to jackson-user


string with hexadecimal digits is valid, but jackson can not pase these values.
Is there a solution or did i miss something?


final ObjectMapper mapper = new ObjectMapper();
//        mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
//        mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        String json1 = "{\"message\":\"h\u0001ellotest\"}";
       
Obj jsonUsers = mapper.readValue(json1.getBytes(),Obj.class);

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 1)): has to be escaped using backslash to be included in string value
 at
[Source: [B@6f1fba17; line: 1, column: 15] (through reference chain: j8.Obj["message"])
        at com
.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)
        at com
.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)
        at com
.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1474)
        at com
.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:260)
        at com
.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
        at com
.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
        at com
.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2819)
        at j8
.JacksonTest.main(JacksonTest.java:24)


Tatu Saloranta

unread,
Apr 17, 2018, 11:04:26 AM4/17/18
to jackson-user
On Mon, Apr 16, 2018 at 11:31 PM, <hil...@gmail.com> wrote:


string with hexadecimal digits is valid, but jackson can not pase these values.
Is there a solution or did i miss something?

Yes, you are tripped by javac :)

You are not including string with character escape, but literal Unicode character with value 0x1, which is a control character
(and excluded as per diagram).

You would need to double-escape value in source code a la:
   String json1 = "{\"message\":\"h\\u0001ellotest\"}";

-+ Tatu +-

 

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages