private void addDefaultSerializers(List<? extends Serializer<?>> serializers) { if (serializers != null) { for (Serializer<?> serializer : serializers) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Serializer.class, serializer.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, serializer.getClass()); if (!serializersMap.containsKey(typeOfConverter)) serializersMap.put(typeOfConverter, serializer); } } }
private void addDefaultDeserializers(List<? extends Deserializer<?>> deserializers) { if (deserializers != null) { for (Deserializer<?> deserializer : deserializers) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Deserializer.class, deserializer.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, deserializer.getClass()); if (!deserializersMap.containsKey(typeOfConverter)) deserializersMap.put(typeOfConverter, deserializer); } } }
private void addDefaultSerializers(List<? extends Serializer<?>> serializers) { if (serializers != null) { for (Serializer<?> serializer : serializers) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Serializer.class, serializer.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, serializer.getClass()); if (!serializersMap.containsKey(typeOfConverter)) serializersMap.put(typeOfConverter, serializer); } } }
private void addDefaultDeserializers(List<? extends Deserializer<?>> deserializers) { if (deserializers != null) { for (Deserializer<?> deserializer : deserializers) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Deserializer.class, deserializer.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, deserializer.getClass()); if (!deserializersMap.containsKey(typeOfConverter)) deserializersMap.put(typeOfConverter, deserializer); } } }
public Trilean isMutator(Method method, Class<?> baseClass) { Type expectedType = TypeUtil.lookupGenericType(BeanView.class, baseClass); expectedType = TypeUtil.expandType(expectedType, baseClass); expectedType = TypeUtil.typeOf(0, expectedType); int modifiers = method.getModifiers(); return Trilean.valueOf(method.getName().startsWith("set") && void.class.equals(method.getReturnType()) && method.getGenericParameterTypes().length == 2 && TypeUtil.match(expectedType, method.getGenericParameterTypes()[1], false) && Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isNative(modifiers)); }
public Trilean isMutator(Method method, Class<?> baseClass) { Type expectedType = TypeUtil.lookupGenericType(BeanView.class, baseClass); expectedType = TypeUtil.expandType(expectedType, baseClass); expectedType = TypeUtil.typeOf(0, expectedType); int modifiers = method.getModifiers(); return Trilean.valueOf(method.getName().startsWith("set") && void.class.equals(method.getReturnType()) && method.getGenericParameterTypes().length == 2 && TypeUtil.match(expectedType, method.getGenericParameterTypes()[1], false) && Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isNative(modifiers)); }
public Trilean isAccessor(Method method, Class<?> baseClass) { Type expectedType = TypeUtil.lookupGenericType(BeanView.class, baseClass); expectedType = TypeUtil.expandType(expectedType, baseClass); expectedType = TypeUtil.typeOf(0, expectedType); int modifiers = method.getModifiers(); return Trilean.valueOf((method.getName().startsWith("get") || (method.getName() .startsWith("is") && (TypeUtil.match(method.getGenericReturnType(), Boolean.class, false) || boolean.class.equals(method.getReturnType())))) && TypeUtil.match(expectedType, method.getGenericParameterTypes()[0], false) && Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isNative(modifiers)); }
public Trilean isAccessor(Method method, Class<?> baseClass) { Type expectedType = TypeUtil.lookupGenericType(BeanView.class, baseClass); expectedType = TypeUtil.expandType(expectedType, baseClass); expectedType = TypeUtil.typeOf(0, expectedType); int modifiers = method.getModifiers(); return Trilean.valueOf((method.getName().startsWith("get") || (method.getName() .startsWith("is") && (TypeUtil.match(method.getGenericReturnType(), Boolean.class, false) || boolean.class.equals(method.getReturnType())))) && TypeUtil.match(expectedType, method.getGenericParameterTypes()[0], false) && Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isNative(modifiers)); }
public GensonBuilder withSerializers(Serializer<?>... serializer) { for (Serializer<?> s : serializer) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Serializer.class, s.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, s.getClass()); registerSerializer(s, typeOfConverter); } return this; }
public GensonBuilder withSerializers(Serializer<?>... serializer) { for (Serializer<?> s : serializer) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Serializer.class, s.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, s.getClass()); registerSerializer(s, typeOfConverter); } return this; }
public GensonBuilder withDeserializers(Deserializer<?>... deserializer) { for (Deserializer<?> d : deserializer) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Deserializer.class, d.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, d.getClass()); registerDeserializer(d, typeOfConverter); } return this; }
public GensonBuilder withDeserializers(Deserializer<?>... deserializer) { for (Deserializer<?> d : deserializer) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Deserializer.class, d.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, d.getClass()); registerDeserializer(d, typeOfConverter); } return this; }
/** * Registers converters mapping them to their corresponding parameterized type. * * @param converter * @return a reference to this builder. */ public GensonBuilder withConverters(Converter<?>... converter) { for (Converter<?> c : converter) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Converter.class, c.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, c.getClass()); registerConverter(c, typeOfConverter); } return this; }
/** * Registers converters mapping them to their corresponding parameterized type. * * @param converter * @return a reference to this builder. */ public GensonBuilder withConverters(Converter<?>... converter) { for (Converter<?> c : converter) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Converter.class, c.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, c.getClass()); registerConverter(c, typeOfConverter); } return this; }
public PropertyMutator createMutator(String name, Method method, Type ofType, Genson genson) { // the target bean must be second parameter for beanview mutators BeanView<?> beanview = views.get(getRawClass(ofType)); if (beanview != null) { Type superTypeWithParameter = TypeUtil.lookupGenericType(BeanView.class, beanview.getClass()); Class<?> tClass = getRawClass(typeOf(0, expandType(superTypeWithParameter, beanview.getClass()))); Type type = expandType(method.getGenericParameterTypes()[0], ofType); return new BeanViewPropertyMutator(name, method, type, beanview, tClass); } else return null; }
public PropertyMutator createMutator(String name, Method method, Type ofType, Genson genson) { // the target bean must be second parameter for beanview mutators BeanView<?> beanview = views.get(getRawClass(ofType)); if (beanview != null) { Type superTypeWithParameter = TypeUtil.lookupGenericType(BeanView.class, beanview.getClass()); Class<?> tClass = getRawClass(typeOf(0, expandType(superTypeWithParameter, beanview.getClass()))); Type type = expandType(method.getGenericParameterTypes()[0], ofType); return new BeanViewPropertyMutator(name, method, type, beanview, tClass); } else return null; }
public PropertyAccessor createAccessor(String name, Method method, Type ofType, Genson genson) { // the target bean must be first (and single) parameter for beanview accessors BeanView<?> beanview = views.get(getRawClass(ofType)); if (beanview != null) { Type superTypeWithParameter = TypeUtil.lookupGenericType(BeanView.class, beanview.getClass()); Class<?> tClass = getRawClass(typeOf(0, expandType(superTypeWithParameter, beanview.getClass()))); Type type = expandType(method.getGenericReturnType(), ofType); return new BeanViewPropertyAccessor(name, method, type, beanview, tClass); } else return null; }
public PropertyAccessor createAccessor(String name, Method method, Type ofType, Genson genson) { // the target bean must be first (and single) parameter for beanview accessors BeanView<?> beanview = views.get(getRawClass(ofType)); if (beanview != null) { Type superTypeWithParameter = TypeUtil.lookupGenericType(BeanView.class, beanview.getClass()); Class<?> tClass = getRawClass(typeOf(0, expandType(superTypeWithParameter, beanview.getClass()))); Type type = expandType(method.getGenericReturnType(), ofType); return new BeanViewPropertyAccessor(name, method, type, beanview, tClass); } else return null; }
@SuppressWarnings("unchecked") protected Class<? extends BeanView<T>> findViewFor(Type type, List<Class<? extends BeanView<?>>> views) { for (Class<? extends BeanView<?>> v : views) { Type searchedType = TypeUtil.lookupGenericType(BeanView.class, v); searchedType = TypeUtil.expandType(searchedType, v); searchedType = TypeUtil.typeOf(0, searchedType); if (TypeUtil.match(type, searchedType, false)) { return (Class<? extends BeanView<T>>) v; } } return null; }
@SuppressWarnings("unchecked") protected Class<? extends BeanView<T>> findViewFor(Type type, List<Class<? extends BeanView<?>>> views) { for (Class<? extends BeanView<?>> v : views) { Type searchedType = TypeUtil.lookupGenericType(BeanView.class, v); searchedType = TypeUtil.expandType(searchedType, v); searchedType = TypeUtil.typeOf(0, searchedType); if (TypeUtil.match(type, searchedType, false)) { return (Class<? extends BeanView<T>>) v; } } return null; }