{"record":{"id":"00cf007e076c2c1a","repo":"OpenFeign/feign","slug":"failure-encoding-object-into-query-map-00cf00","errorCode":null,"errorMessage":"Failure encoding object into query map","messagePattern":"Failure encoding object into query map","errorType":"exception","errorClass":"EncodeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/querymap/FieldQueryMapEncoder.java","lineNumber":65,"sourceCode":"    ObjectParamMetadata metadata =\n        classToMetadata.computeIfAbsent(object.getClass(), ObjectParamMetadata::parseObjectType);\n\n    return metadata.objectFields.stream()\n        .map(field -> this.FieldValuePair(object, field))\n        .filter(fieldObjectPair -> fieldObjectPair.right.isPresent())\n        .collect(Collectors.toMap(this::fieldName, fieldObjectPair -> fieldObjectPair.right.get()));\n  }\n\n  private String fieldName(Pair<Field, Optional<Object>> pair) {\n    Param alias = pair.left.getAnnotation(Param.class);\n    return alias != null ? alias.value() : pair.left.getName();\n  }\n\n  private Pair<Field, Optional<Object>> FieldValuePair(Object object, Field field) {\n    try {\n      return Pair.pair(field, Optional.ofNullable(field.get(object)));\n    } catch (IllegalAccessException e) {\n      throw new EncodeException(\"Failure encoding object into query map\", e);\n    }\n  }\n\n  private static class ObjectParamMetadata {\n\n    private final List<Field> objectFields;\n\n    private ObjectParamMetadata(List<Field> objectFields) {\n      this.objectFields = Collections.unmodifiableList(objectFields);\n    }\n\n    private static ObjectParamMetadata parseObjectType(Class<?> type) {\n      List<Field> allFields = new ArrayList();\n\n      for (Class currentClass = type;\n          currentClass != null;\n          currentClass = currentClass.getSuperclass()) {\n        Collections.addAll(allFields, currentClass.getDeclaredFields());","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/querymap/FieldQueryMapEncoder.java#L47-L83","documentation":"FieldQueryMapEncoder reads an object's fields reflectively (field.get(object)) to build a query-parameter map. When a field is not accessible to the encoder, the IllegalAccessException is wrapped in EncodeException with this message, failing request encoding.","triggerScenarios":"Encoding a @QueryMap object whose fields cannot be read via Field.get — e.g., a non-public class with public fields, or fields made inaccessible under restrictive access/module checks — during Feign request creation.","commonSituations":"Using package-private or private classes as @QueryMap objects (field.get fails even for public fields because the declaring class is not accessible); JPMS strong encapsulation hiding the class; field values themselves never throw, so the cause is almost always IllegalAccessException.","solutions":["Make the @QueryMap object's class public (a public class with package-private fields is fine for field access); rethrowing happens on Field.get so class accessibility is key","Inspect the wrapped cause via EncodeException.getCause() to identify the offending field/class","Catch EncodeException around request execution and log it before retrying","Alternatively switch to BeanQueryMapEncoder or an explicit Map<String, Object> for the query parameters"],"exampleFix":"// before\n// package-private class used as @QueryMap\nclass SearchParams { public String q; public int limit; }\n// after\npublic class SearchParams { public String q; public int limit; } // public class so Field.get succeeds","handlingStrategy":"try-catch","validationCode":"if (!Modifier.isPublic(params.getClass().getModifiers())) {\n  throw new IllegalStateException(\"@QueryMap object class must be public: \" + params.getClass());\n}","typeGuard":"boolean isFieldAccessible(Object o) {\n  return o != null && Modifier.isPublic(o.getClass().getModifiers());\n}","tryCatchPattern":"try {\n  api.search(params);\n} catch (EncodeException e) {\n  throw new IllegalArgumentException(\"query map field not readable: \" + e.getCause(), e);\n}","preventionTips":["Declare @QueryMap objects as public top-level or public static nested classes","Check getCause() (IllegalAccessException) to identify the inaccessible field","Prefer Map<String, Object> or BeanQueryMapEncoder when class accessibility is uncertain"],"tags":["java","feign","reflection","encoding","query-map"],"backgroundTag":"json-marshal-failed","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}