Deserializer { public Resource setIdField(Resource resourceObject, Object data) throws NotExtendingResourceException { Class superClass = null; try { superClass = getMorpheusResourceSuperClass(resourceObject); } catch (NotExtendingResourceException e) { throw e; } try { Field field = superClass.getDeclaredField("Id"); field.setAccessible(true); if (data instanceof String) { field.set(resourceObject, data); } else { field.set(resourceObject, String.valueOf(data)); } } catch (NoSuchFieldException e) { Logger.debug("No field Id found. That should not happened."); } catch (IllegalAccessException e) { Logger.debug("Could not access field Id"); } return resourceObject; }  static void registerResourceClass(String typeName, Class resourceClass); Resource createObjectFromString(String resourceName); Resource setField(Resource resourceObject, String fieldName, Object data); Resource setIdField(Resource resourceObject, Object data); static HashMap<String, Class> getRegisteredClasses(); static void setRegisteredClasses(HashMap<String, Class> registeredClasses);  }
@Test public void testSetIdField() throws Exception { Deserializer deserializer = new Deserializer(); Article article = new Article(); Resource resource = deserializer.setIdField(article, "123456"); article = (Article)resource; assertEquals(article.getId(), "123456"); }
@Test public void testSetIdFieldNumber() throws Exception { Deserializer deserializer = new Deserializer(); Article article = new Article(); Resource resource = deserializer.setIdField(article, 123456); article = (Article)resource; assertEquals(article.getId(), "123456"); }
@Test public void testSetIdFieldMultiExtendingClass() throws Exception { Deserializer deserializer = new Deserializer(); MultiExtendResource multiExtendResource= new MultiExtendResource(); Resource resource = deserializer.setIdField(multiExtendResource, 123456); multiExtendResource = (MultiExtendResource)resource; assertEquals(multiExtendResource.getId(), "123456"); }