private static Method getFactoryMethod(Class<?> clazz, Method[] methods) { Method factoryMethod = null; for (Method method : methods) { if (!Modifier.isStatic(method.getModifiers())) { continue; } if (!clazz.isAssignableFrom(method.getReturnType())) { continue; } JSONCreator annotation = method.getAnnotation(JSONCreator.class); if (annotation != null) { if (factoryMethod != null) { throw new JSONException("multi-JSONCreator"); } factoryMethod = method; // 不应该break,否则多个静态工厂方法上存在 JSONCreator 注解时,并不会触发上述异常抛出 } } return factoryMethod; }
/** * 支付商户信息 * * @param id 公众号唯一的身份ID(必填) * @param secret 公众号调用接口的凭证(最好填写) * @param paySignKey 支付密钥字符串(必填) * @param mchId 微信支付分配的商户号(必填) * @param certificateKey 加载支付证书文件的密码(默认为商户号) * @param deviceInfo 微信支付分配的设备号(非必填) * @param partnerId 财付通的商户号(非必填) * @param subId 微信分配的子商户公众账号ID(非必填) * @param subMchId 微信支付分配的子商户号(非必填) */ @JSONCreator public WeixinPayAccount(@JSONField(name = "id") String id, @JSONField(name = "secret") String secret, @JSONField(name = "paySignKey") String paySignKey, @JSONField(name = "mchId") String mchId, @JSONField(name = "certificateKey") String certificateKey, @JSONField(name = "deviceInfo") String deviceInfo, @JSONField(name = "partnerId") String partnerId, @JSONField(name = "subId") String subId, @JSONField(name = "subMchId") String subMchId) { super(id, secret); this.paySignKey = paySignKey; this.mchId = mchId; this.certificateKey = certificateKey; this.deviceInfo = deviceInfo; this.partnerId = partnerId; this.subId = subId; this.subMchId = subMchId; }
public static Constructor<?> getCreatorConstructor(Class<?> clazz) { Constructor[] declaredConstructors = clazz.getDeclaredConstructors(); int length = declaredConstructors.length; int i = 0; while (i < length) { Constructor<?> constructor = declaredConstructors[i]; if (((JSONCreator) constructor.getAnnotation(JSONCreator.class)) == null) { i++; } else if (null == null) { return constructor; } else { throw new JSONException("multi-json creator"); } } return null; }
public static Method getFactoryMethod(Class<?> clazz) { Method[] declaredMethods = clazz.getDeclaredMethods(); int length = declaredMethods.length; int i = 0; while (i < length) { Method method = declaredMethods[i]; if (!Modifier.isStatic(method.getModifiers()) || !clazz.isAssignableFrom(method.getReturnType()) || ((JSONCreator) method.getAnnotation(JSONCreator.class)) == null) { i++; } else if (null == null) { return method; } else { throw new JSONException("multi-json creator"); } } return null; }
public static Constructor<?> getCreatorConstructor(Class<?> clazz) { Constructor<?> creatorConstructor = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { JSONCreator annotation = constructor.getAnnotation(JSONCreator.class); if (annotation != null) { if (creatorConstructor != null) { throw new JSONException("multi-json creator"); } creatorConstructor = constructor; break; } } return creatorConstructor; }
public static Method getFactoryMethod(Class<?> clazz) { Method factoryMethod = null; for (Method method : clazz.getDeclaredMethods()) { if (!Modifier.isStatic(method.getModifiers())) { continue; } if (!clazz.isAssignableFrom(method.getReturnType())) { continue; } JSONCreator annotation = method.getAnnotation(JSONCreator.class); if (annotation != null) { if (factoryMethod != null) { throw new JSONException("multi-json creator"); } factoryMethod = method; break; } } return factoryMethod; }
@JSONCreator public VO(@JSONField(name = "b") boolean b, @JSONField(name = "i") int i, @JSONField(name = "l") long l, @JSONField(name = "f") float f){ super(); this.b = b; this.i = i; this.l = l; this.f = f; }
@JSONCreator public static V1 create(@JSONField(name = "b") boolean b, @JSONField(name = "i") int i, @JSONField(name = "l") long l, @JSONField(name = "f") float f) { V1 v = new V1(b); v.i = i; v.l = l; v.f = f; return v; }
@JSONCreator public HostPoint(@JSONField(name = "address") HostAddress addr) { this.address = addr; }
@JSONCreator public Fingerprint(@JSONField(name = "source") String fingerprint) { this.source = fingerprint; }
@JSONCreator public static V1 create(@JSONField(name = "b") boolean b, @JSONField(name = "i") int i, @JSONField(name = "l") long l, @JSONField(name = "f") float f) { throw new IllegalStateException(); }
@JSONCreator public Entity(@JSONField(name = "value") Map<Object, Map<Object, Object>> value){ this.value = value; }
@JSONCreator public Entity(@JSONField(name="f1") int f1, @JSONField(name="f2") Integer f2){ this.f1 = f1; this.f2 = f2; }
@JSONCreator public Entity(@JSONField(name = "f1") Boolean f1, @JSONField(name = "f2") Boolean f2){ this.f1 = f1; this.f2 = f2; }
@JSONCreator public Entity(@JSONField(name = "f1") long f1, @JSONField(name = "f2") Long f2){ this.f1 = f1; this.f2 = f2; }
@JSONCreator public Entity(@JSONField(name = "id") int id) { this.id = id; }
@JSONCreator public Entity(@JSONField(name = "values") List<Value> values){ this.values = values; }
@JSONCreator public Entity(@JSONField(name = "id") int id, @JSONField(name = "child") Child child){ super(); this.id = id; this.child = child; }
@JSONCreator public Foo(@JSONField(name = "foo") final String bar){ this.bar = bar; }
@JSONCreator public static AbstractModel createInstance() { return new Model(); }
@JSONCreator public WeixinAccount(@JSONField(name = "id") String id, @JSONField(name = "secret") String secret) { this.id = id; this.secret = secret; }
@JSONCreator public TestException() { }