{"record":{"id":"2138417451662ede","repo":"OpenFeign/feign","slug":"failure-encoding-object-into-query-map","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/BeanQueryMapEncoder.java","lineNumber":60,"sourceCode":"  public Map<String, Object> encode(Object object) throws EncodeException {\n    if (object == null) {\n      return Collections.emptyMap();\n    }\n    try {\n      ObjectParamMetadata metadata = getMetadata(object.getClass());\n      Map<String, Object> propertyNameToValue = new HashMap<String, Object>();\n      for (PropertyDescriptor pd : metadata.objectProperties) {\n        Method method = pd.getReadMethod();\n        Object value = method.invoke(object);\n        if (value != null && value != object) {\n          Param alias = method.getAnnotation(Param.class);\n          String name = alias != null ? alias.value() : pd.getName();\n          propertyNameToValue.put(name, value);\n        }\n      }\n      return propertyNameToValue;\n    } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) {\n      throw new EncodeException(\"Failure encoding object into query map\", e);\n    }\n  }\n\n  private ObjectParamMetadata getMetadata(Class<?> objectType) throws IntrospectionException {\n    ObjectParamMetadata metadata = classToMetadata.get(objectType);\n    if (metadata == null) {\n      metadata = ObjectParamMetadata.parseObjectType(objectType);\n      classToMetadata.put(objectType, metadata);\n    }\n    return metadata;\n  }\n\n  private static class ObjectParamMetadata {\n\n    private final List<PropertyDescriptor> objectProperties;\n\n    private ObjectParamMetadata(List<PropertyDescriptor> objectProperties) {\n      this.objectProperties = Collections.unmodifiableList(objectProperties);","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/querymap/BeanQueryMapEncoder.java#L42-L78","documentation":"BeanQueryMapEncoder converts a bean-style object into a query-parameter map by reading its properties via the JavaBeans Introspector. If reflection on the bean fails — a getter is not accessible, introspection of the class fails, or the underlying getter throws — Feign wraps the cause in EncodeException with this message.","triggerScenarios":"Calling Feign with a @QueryMap-bound bean whose getters throw, whose property descriptors cannot be introspected (IntrospectionException), or whose getter method is inaccessible to the encoder (IllegalAccessException / InvocationTargetException).","commonSituations":"Passing non-bean or oddly-shaped objects (no public getters) as @QueryMap; beans with getter methods that throw NPEs on internal state; running under a SecurityManager/strict module access that blocks reflective getter calls; class changes after introspection metadata was cached.","solutions":["Fix or remove the getter on the query-map bean that throws the wrapped InvocationTargetException","Ensure query-map objects are proper JavaBeans: public class with public no-arg constructor and public getters","Catch EncodeException around the Feign call and inspect getCause() to identify which property failed","Make the bean class/methods accessible (public) if IllegalAccessException is the cause"],"exampleFix":"// before\nFeign.builder().queryMapEncoder(new BeanQueryMapEncoder())\n  .target(Api.class, \"https://api\");\n// used with a class whose getter throws:\npublic class Params { public String getQ() { throw new IllegalStateException(\"uninitialized\"); } }\n// after\npublic class Params {\n  private String q = \"\";\n  public String getQ() { return q; } // getter must not throw\n  public void setQ(String q) { this.q = q; }\n}","handlingStrategy":"try-catch","validationCode":"for (PropertyDescriptor pd : Introspector.getBeanInfo(params.getClass()).getPropertyDescriptors()) {\n  if (pd.getReadMethod() == null || !Modifier.isPublic(pd.getReadMethod().getDeclaringClass().getModifiers()))\n    throw new IllegalStateException(\"query-map bean property not readable: \" + pd.getName());\n}","typeGuard":"boolean isValidQueryMapBean(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(\"bad query map bean: \" + e.getCause(), e);\n}","preventionTips":["Use proper JavaBeans: public class, public getters, no-arg constructor","Keep getters side-effect free; never throw from them","Keep query-map values initialized before calling the client","Log getCause() when wrapping EncodeException to find the failing property"],"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"}