ServiceTools { Object getInstanceOfClass(Class cls) { if (Boolean.class.isAssignableFrom(cls) || Boolean.TYPE.isAssignableFrom(cls)) { return Boolean.FALSE; } else if (Integer.TYPE.isAssignableFrom(cls) || Short.TYPE.isAssignableFrom(cls) || Integer.class.isAssignableFrom(cls) || Short.class.isAssignableFrom(cls)) { return 0; } else if (Long.TYPE.isAssignableFrom(cls) || Long.class.isAssignableFrom(cls)) { return 0L; } else if (Float.TYPE.isAssignableFrom(cls) || Float.class.isAssignableFrom(cls)) { return 0.1F; } else if (Double.TYPE.isAssignableFrom(cls) || Double.class.isAssignableFrom(cls)) { return 0.1D; } else if (cls.isArray()) { Class<?> comp = cls.getComponentType(); Object instance = getInstanceOfClass(comp); return new Object[]{instance, instance}; } else { try { return cls.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { return getObjectFromConstantFields(cls); } } }  String getShortName(String fullformat); String getLiteralType(Type type); IJsonMarshaller getJsonMarshaller(Annotation[] annotations); IJsonMarshaller getJsonMarshallerFromAnnotation(JsonUnmarshaller jua); String getTemplateOfType(Type type, IJsonMarshaller jsonMarshaller); String getInstanceNameFromDataservice(Class cls); boolean isConsiderateMethod(Method method);  }
@Test public void testGetInstanceOfClass() throws JsonProcessingException { System.out.println("getTemplateOfClass"); ObjectMapper om = new ObjectMapper(); Result r = new Result(); String expResult = om.writeValueAsString(r); Class cls = Boolean.class; Object result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Boolean.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Integer.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Integer.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Long.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0L); cls = Long.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0l); cls = Float.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Float.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Double.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Double.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Float[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(new Float[]{0.1f, 0.1f}); cls = Result.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(r); cls = Result[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(new Result[] {r, r}); cls = Locale.class; result = instance.getInstanceOfClass(cls); assertThat(result).isInstanceOf(Locale.class); cls = Serializable.class; result = instance.getInstanceOfClass(cls); assertThat(result).isNull(); }