{"id":"1db09fffc57a683b","repo":"google/gson","slug":"failed-parsing-s-as-uuid-at-path-in","errorCode":null,"errorMessage":"Failed parsing '\" + s + \"' as UUID; at path \" + in.getPreviousPath()","messagePattern":"Failed parsing '\" \\+ s \\+ \"' as UUID; at path \" \\+ in\\.getPreviousPath\\(\\)","errorType":"exception","errorClass":"JsonSyntaxException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java","lineNumber":792,"sourceCode":"        }\n      };\n\n  public static final TypeAdapterFactory INET_ADDRESS_FACTORY =\n      newTypeHierarchyFactory(InetAddress.class, INET_ADDRESS);\n\n  public static final TypeAdapter<UUID> UUID =\n      new TypeAdapter<UUID>() {\n        @Override\n        public UUID read(JsonReader in) throws IOException {\n          if (in.peek() == JsonToken.NULL) {\n            in.nextNull();\n            return null;\n          }\n          String s = in.nextString();\n          try {\n            return java.util.UUID.fromString(s);\n          } catch (IllegalArgumentException e) {\n            throw new JsonSyntaxException(\n                \"Failed parsing '\" + s + \"' as UUID; at path \" + in.getPreviousPath(), e);\n          }\n        }\n\n        @Override\n        public void write(JsonWriter out, UUID value) throws IOException {\n          out.value(value == null ? null : value.toString());\n        }\n      };\n\n  public static final TypeAdapterFactory UUID_FACTORY = newFactory(UUID.class, UUID);\n\n  public static final TypeAdapter<Currency> CURRENCY =\n      new TypeAdapter<Currency>() {\n        @Override\n        public Currency read(JsonReader in) throws IOException {\n          String s = in.nextString();\n          try {","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/google/gson/blob/8b8628c65699bc4421696183c62ae0c1b9b281dc/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java#L774-L810","documentation":"Gson's UUID TypeAdapter reads the JSON string and calls java.util.UUID.fromString, which requires the canonical 36-character hyphenated form. Any deviation throws IllegalArgumentException, wrapped by Gson as JsonSyntaxException with the bad string and JSON path.","triggerScenarios":"Deserializing a JSON string into a UUID field when the string is not a valid 8-4-4-4-12 hex representation (wrong length, missing hyphens, non-hex chars, extra braces).","commonSituations":"Producer emits a stripped UUID (no hyphens), a URN prefix 'urn:uuid:...', curly braces from .NET GUIDs, uppercase being fine but extra whitespace, or a different field mistakenly mapped.","solutions":["Normalize the input to canonical form before Gson: trim, strip 'urn:uuid:'/'{}', re-insert hyphens for 32-char hex.","Register a custom TypeAdapter<UUID> that performs the normalization and then calls UUID.fromString.","Correct the upstream producer to emit canonical 8-4-4-4-12 UUIDs."],"exampleFix":"// before\nUUID id = gson.fromJson(\"\\\"550e8400e29b41d4a716446655440000\\\"\", UUID.class);\n\n// after\nGson gson = new GsonBuilder().registerTypeHierarchyAdapter(UUID.class, new JsonDeserializer<UUID>() {\n    @Override public UUID deserialize(JsonElement j, Type t, JsonDeserializationContext c) {\n        String s = j.getAsString().replace(\"urn:uuid:\", \"\").replace(\"{\", \"\").replace(\"}\", \"\").trim();\n        if (s.length() == 32) s = s.replaceAll(\"(.{8})(.{4})(.{4})(.{4})(.{12})\", \"$1-$2-$3-$4-$5\");\n        return UUID.fromString(s);\n    }\n}).create();","handlingStrategy":"validation","validationCode":"boolean isParsableUuid(String s) {\n  if (s == null) return false;\n  try { UUID.fromString(s); return true; } catch (IllegalArgumentException e) { return false; }\n}","typeGuard":"static boolean isCanonicalUuid(String s) {\n  return s != null && s.matches(\"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\");\n}","tryCatchPattern":"try {\n  UUID u = gson.fromJson(json, UUID.class);\n} catch (JsonSyntaxException e) {\n  // normalize (strip braces/urn, re-hyphenate 32-hex) and retry once\n}","preventionTips":["Normalize incoming UUIDs to canonical 8-4-4-4-12 hex before Gson.","Register a tolerant UUID TypeAdapter once at Gson construction.","Validate at API boundaries with a shared helper."],"tags":["gson","deserialization","uuid","json"],"analyzedSha":"8b8628c65699bc4421696183c62ae0c1b9b281dc","analyzedAt":"2026-08-04T19:12:22.202Z","schemaVersion":2}