{"id":"355bdb6c646a934b","repo":"google/gson","slug":"missing-fieldname-field-at-path-path","errorCode":null,"errorMessage":"Missing {fieldName} field; at path {path}","messagePattern":"Missing (.+?) field; at path (.+?)","errorType":"exception","errorClass":"JsonSyntaxException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/internal/bind/JavaTimeTypeAdapters.java","lineNumber":444,"sourceCode":"          } else if (rawType == ZoneId.class || rawType == ZoneOffset.class) {\n            // We don't check ZoneId.class.isAssignableFrom(rawType) because we don't want to match\n            // the non-public class ZoneRegion in the runtime type check in\n            // TypeAdapterRuntimeTypeWrapper.write. If we did, then our ZONE_ID would take\n            // precedence over a ZoneId adapter that the user might have registered. (This exact\n            // situation showed up in a Google-internal test.)\n            adapter = ZONE_ID;\n          } else if (rawType == ZonedDateTime.class) {\n            adapter = zonedDateTime(gson);\n          }\n          @SuppressWarnings(\"unchecked\")\n          TypeAdapter<T> result = (TypeAdapter<T>) adapter;\n          return result;\n        }\n      };\n\n  private static <T> T requireNonNullField(T field, String fieldName, JsonReader reader) {\n    if (field == null) {\n      throw new JsonSyntaxException(\n          \"Missing \" + fieldName + \" field; at path \" + reader.getPreviousPath());\n    }\n    return field;\n  }\n}\n","sourceCodeStart":426,"sourceCodeEnd":450,"githubUrl":"https://github.com/google/gson/blob/8b8628c65699bc4421696183c62ae0c1b9b281dc/gson/src/main/java/com/google/gson/internal/bind/JavaTimeTypeAdapters.java#L426-L450","documentation":"Thrown by JavaTimeTypeAdapters.requireNonNullField when a required subfield {fieldName} is absent while deserializing a composite java.time type. The composite adapters (LocalDateTime, OffsetDateTime, OffsetTime, ZonedDateTime) build the value from named sub-objects; if one of date/time/dateTime/offset/zone is missing the build cannot proceed. The {path} is the reader's previous path.","triggerScenarios":"Deserializing a LocalDateTime whose JSON object has 'time' but no 'date'; an OffsetDateTime missing 'dateTime' or 'offset'; a ZonedDateTime missing 'dateTime', 'offset', or 'zone'. The producer omitted or misspelled one of the required keys.","commonSituations":"Producer trims null subfields; rename between API versions (e.g. 'localDateTime' vs 'dateTime'); partial deserialization of a log; client/server running different Gson versions that disagree on the field layout.","solutions":["Make the producer emit all required subfields with the exact keys Gson expects (date/time for LocalDateTime; dateTime/offset for OffsetDateTime; dateTime/offset/zone for ZonedDateTime).","Register a custom TypeAdapter for the java.time type that maps the producer's actual key names.","If the value can legitimately be missing, model the field as nullable and have the producer send JSON null.","Pre-scan the JSON object for the required keys and report a data-contract error to the producer."],"exampleFix":"// before: '{\"time\":{\"hour\":10}}'  -> Missing date field\n// after: include all required sub-objects\nString json = \"{\\\"date\\\":{\\\"year\\\":2025,\\\"month\\\":1,\\\"day\\\":5},\"\n            + \"\\\"time\\\":{\\\"hour\\\":10,\\\"minute\\\":0,\\\"second\\\":0,\\\"nano\\\":0}}\";\nLocalDateTime ldt = gson.fromJson(json, LocalDateTime.class);","handlingStrategy":"validation","validationCode":"// Pre-check composite java.time objects have required subfields\nJsonObject o = JsonParser.parseString(json).getAsJsonObject();\nif (!o.has(\"date\") || !o.has(\"time\")) {\n  throw new IllegalArgumentException(\"LocalDateTime JSON missing date or time\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return gson.fromJson(json, LocalDateTime.class);\n} catch (JsonSyntaxException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Missing \") && e.getMessage().contains(\"field\")) {\n    throw new InvalidPayloadException(\"Incomplete java.time JSON: \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Ensure the producer emits all required subfields (or explicit null).","Keep API versions aligned on the composite field layout.","Write schema tests for the java.time JSON representation."],"tags":["java-time","deserialization","missing-field","data-contract"],"analyzedSha":"8b8628c65699bc4421696183c62ae0c1b9b281dc","analyzedAt":"2026-08-04T19:12:22.202Z","schemaVersion":2}