无法使用 mapper.readValue 将有效的 UUID 字符串转换为 UUID

Cannot convert a valid UUID string to UUID using mapper.readValue

我有一个字符串格式的有效 UUID

7a041f81-1214-41e5-bb58-9a46b2ca08d4

但是当我使用 ObjectMapper 将其转换为 UUID 时,我一直收到此错误。

    UUID uuid = mapper.readValue("7a041f81-1214-41e5-bb58-9a46b2ca08d4",UUID.class);

错误:

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('a' (code 97)): Expected space separating root-level values at [Source: (String)"7a041f81-1214-41e5-bb58-9a46b2ca08d4"; line: 1, column: 3] at com.xxxx.yyyyy.zzzzz.Test.callTest(BmcEventListenerTest.java:22

如何将字符串转换为 UUID,为什么我总是收到此错误?

您不需要对象映射器,您可以执行以下操作

UUID obj = UUID.fromString("7a041f81-1214-41e5-bb58-9a46b2ca08d4"); 

演示:https://onecompiler.com/java/3v2sr8pk8