@Test public void testDecode() throws Exception { JSONAnnotationDecoder decoder = new JSONAnnotationDecoder(); AnnotatedSetTestClass result = decoder.decode(AnnotatedSetTestClass.class, "{\"test1\":\"mytestvalue\",\"test2\":true,\"test3\":true," + "\"nested\":{\"mystring\":\"blubber\"}," + "\"nestedStringList\":[\"nested1\",\"nested2\",\"nested3\"]," + "\"primitiveString\":[\"nestedX1\",\"nestedX2\",\"nestedX3\"]" + "}"); Assert.assertEquals("mytestvalue",result.getTest1()); Assert.assertEquals(true,result.isTest2()); Assert.assertEquals(Boolean.TRUE,result.getTest3()); Assert.assertEquals("blubber",result.getNested().getMystring()); Assert.assertEquals(3,result.getNestedStringList().size()); Assert.assertEquals(3,result.getPrimitiveString().length); }
public <T> T decode(Class<T> t, final String json) throws JSONException { JSONDecoder decoder = new JSONDecoder(json); JSONValue value = decoder.decode(); JSONObject source = null; if (!(value instanceof JSONObject)) { throw new JSONException("Decoder expected JSON Object String"); } else { source = (JSONObject) value; } T result = null; try { result = t.newInstance(); } catch (InstantiationException e) { throw new JSONException("Could not instantiate class: " + t, e); } catch (IllegalAccessException e) { throw new JSONException("Could not access class: " + t, e); } putObject(result, source); return result; }
JSONAnnotationDecoder { public <T> T decode(Class<T> t, final String json) throws JSONException { JSONDecoder decoder = new JSONDecoder(json); JSONValue value = decoder.decode(); JSONObject source = null; if (!(value instanceof JSONObject)) { throw new JSONException("Decoder expected JSON Object String"); } else { source = (JSONObject) value; } T result = null; try { result = t.newInstance(); } catch (InstantiationException e) { throw new JSONException("Could not instantiate class: " + t, e); } catch (IllegalAccessException e) { throw new JSONException("Could not access class: " + t, e); } putObject(result, source); return result; } }
JSONAnnotationDecoder { public <T> T decode(Class<T> t, final String json) throws JSONException { JSONDecoder decoder = new JSONDecoder(json); JSONValue value = decoder.decode(); JSONObject source = null; if (!(value instanceof JSONObject)) { throw new JSONException("Decoder expected JSON Object String"); } else { source = (JSONObject) value; } T result = null; try { result = t.newInstance(); } catch (InstantiationException e) { throw new JSONException("Could not instantiate class: " + t, e); } catch (IllegalAccessException e) { throw new JSONException("Could not access class: " + t, e); } putObject(result, source); return result; }  }
JSONAnnotationDecoder { public <T> T decode(Class<T> t, final String json) throws JSONException { JSONDecoder decoder = new JSONDecoder(json); JSONValue value = decoder.decode(); JSONObject source = null; if (!(value instanceof JSONObject)) { throw new JSONException("Decoder expected JSON Object String"); } else { source = (JSONObject) value; } T result = null; try { result = t.newInstance(); } catch (InstantiationException e) { throw new JSONException("Could not instantiate class: " + t, e); } catch (IllegalAccessException e) { throw new JSONException("Could not access class: " + t, e); } putObject(result, source); return result; }  T decode(Class<T> t, final String json); }
JSONAnnotationDecoder { public <T> T decode(Class<T> t, final String json) throws JSONException { JSONDecoder decoder = new JSONDecoder(json); JSONValue value = decoder.decode(); JSONObject source = null; if (!(value instanceof JSONObject)) { throw new JSONException("Decoder expected JSON Object String"); } else { source = (JSONObject) value; } T result = null; try { result = t.newInstance(); } catch (InstantiationException e) { throw new JSONException("Could not instantiate class: " + t, e); } catch (IllegalAccessException e) { throw new JSONException("Could not access class: " + t, e); } putObject(result, source); return result; }  T decode(Class<T> t, final String json);  }