@Issue("JENKINS-61438") @Test public void verify_JSON_bind_work_with_setter_that_accept_object_type() throws Exception { final Stapler stapler = new Stapler(); stapler.setWebApp(new WebApp(Mockito.mock(ServletContext.class))); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); RequestImpl req = new RequestImpl(stapler, request, Collections.<AncestorImpl>emptyList(), null); JSONObject json = new JSONObject(); json.put("$class", SetterObject.class.getName()); json.put("choices", "1\n2\n3"); SetterObject o = req.bindJSON(SetterObject.class, json); Assert.assertEquals(o.getChoices(), Arrays.asList("1", "2", "3")); }
public <T> T bindJSON(Class<T> type, JSONObject src) { return type.cast(bindJSON(type, type, src)); }
RequestImpl extends HttpServletRequestWrapper implements StaplerRequest { public <T> T bindJSON(Class<T> type, JSONObject src) { return type.cast(bindJSON(type, type, src)); } }
RequestImpl extends HttpServletRequestWrapper implements StaplerRequest { public <T> T bindJSON(Class<T> type, JSONObject src) { return type.cast(bindJSON(type, type, src)); } RequestImpl(Stapler stapler, HttpServletRequest request, List<AncestorImpl> ancestors, TokenList tokens); }
RequestImpl extends HttpServletRequestWrapper implements StaplerRequest { public <T> T bindJSON(Class<T> type, JSONObject src) { return type.cast(bindJSON(type, type, src)); } RequestImpl(Stapler stapler, HttpServletRequest request, List<AncestorImpl> ancestors, TokenList tokens); boolean isJavaScriptProxyCall(); BoundObjectTable getBoundObjectTable(); String createJavaScriptProxy(Object toBeExported); Stapler getStapler(); WebApp getWebApp(); String getRestOfPath(); String getOriginalRestOfPath(); ServletContext getServletContext(); @Override String getParameter(String name); @Override Map getParameterMap(); @Override Enumeration getParameterNames(); @Override String[] getParameterValues(String name); String getRequestURIWithQueryString(); StringBuffer getRequestURLWithQueryString(); RequestDispatcher getView(Object it,String viewName); RequestDispatcher getView(Class clazz, String viewName); RequestDispatcher getView(Klass<?> clazz, String viewName); RequestDispatcher getView(Klass<?> clazz, Object it, String viewName); String getRootPath(); String getReferer(); List<Ancestor> getAncestors(); Ancestor findAncestor(Class type); T findAncestorObject(Class<T> type); Ancestor findAncestor(Object anc); boolean hasParameter(String name); String getOriginalRequestURI(); boolean checkIfModified(long lastModified, StaplerResponse rsp); boolean checkIfModified(long lastModified, StaplerResponse rsp, long expiration); boolean checkIfModified(Date timestampOfResource, StaplerResponse rsp); boolean checkIfModified(Calendar timestampOfResource, StaplerResponse rsp); BindInterceptor getBindInterceptor(); BindInterceptor setBindListener(BindInterceptor bindListener); BindInterceptor setBindInterceptpr(BindInterceptor bindListener); BindInterceptor setBindInterceptor(BindInterceptor bindListener); void bindParameters(Object bean); void bindParameters(Object bean, String prefix); List<T> bindParametersToList(Class<T> type, String prefix); T bindParameters(Class<T> type, String prefix); T bindParameters(Class<T> type, String prefix, int index); T bindJSON(Class<T> type, JSONObject src); Object bindJSON(Type type, Class erasure, Object json); void bindJSON(Object bean, JSONObject src); List<T> bindJSONToList(Class<T> type, Object src); JSONObject getSubmittedForm(); FileItem getFileItem(String name); }
RequestImpl extends HttpServletRequestWrapper implements StaplerRequest { public <T> T bindJSON(Class<T> type, JSONObject src) { return type.cast(bindJSON(type, type, src)); } RequestImpl(Stapler stapler, HttpServletRequest request, List<AncestorImpl> ancestors, TokenList tokens); boolean isJavaScriptProxyCall(); BoundObjectTable getBoundObjectTable(); String createJavaScriptProxy(Object toBeExported); Stapler getStapler(); WebApp getWebApp(); String getRestOfPath(); String getOriginalRestOfPath(); ServletContext getServletContext(); @Override String getParameter(String name); @Override Map getParameterMap(); @Override Enumeration getParameterNames(); @Override String[] getParameterValues(String name); String getRequestURIWithQueryString(); StringBuffer getRequestURLWithQueryString(); RequestDispatcher getView(Object it,String viewName); RequestDispatcher getView(Class clazz, String viewName); RequestDispatcher getView(Klass<?> clazz, String viewName); RequestDispatcher getView(Klass<?> clazz, Object it, String viewName); String getRootPath(); String getReferer(); List<Ancestor> getAncestors(); Ancestor findAncestor(Class type); T findAncestorObject(Class<T> type); Ancestor findAncestor(Object anc); boolean hasParameter(String name); String getOriginalRequestURI(); boolean checkIfModified(long lastModified, StaplerResponse rsp); boolean checkIfModified(long lastModified, StaplerResponse rsp, long expiration); boolean checkIfModified(Date timestampOfResource, StaplerResponse rsp); boolean checkIfModified(Calendar timestampOfResource, StaplerResponse rsp); BindInterceptor getBindInterceptor(); BindInterceptor setBindListener(BindInterceptor bindListener); BindInterceptor setBindInterceptpr(BindInterceptor bindListener); BindInterceptor setBindInterceptor(BindInterceptor bindListener); void bindParameters(Object bean); void bindParameters(Object bean, String prefix); List<T> bindParametersToList(Class<T> type, String prefix); T bindParameters(Class<T> type, String prefix); T bindParameters(Class<T> type, String prefix, int index); T bindJSON(Class<T> type, JSONObject src); Object bindJSON(Type type, Class erasure, Object json); void bindJSON(Object bean, JSONObject src); List<T> bindJSONToList(Class<T> type, Object src); JSONObject getSubmittedForm(); FileItem getFileItem(String name); final TokenList tokens; final List<AncestorImpl> ancestors; final Stapler stapler; }