@Override public Converter create(BeanProperty property, Genson genson) { if (property.getRawClass().isAssignableFrom(IdRef.class)) { return IdRefConverters.idRefConverter; } if (property.getRawClass().isAssignableFrom(LazyJson.class)) { return LazyJsonConverters.get(property.getName(), property.getType()); } return null; } }
private boolean hasRelevantAnnotation(BeanProperty property){ JsonDateFormat formatAnn = property.getAnnotation(JsonDateFormat.class); JsonZoneId zoneIdAnn = property.getAnnotation(JsonZoneId.class); JsonTimestampFormat timestampFormatAnn = property.getAnnotation(JsonTimestampFormat.class); return formatAnn != null || zoneIdAnn != null || timestampFormatAnn != null; }
protected <T extends BeanProperty> T _mostSpecificPropertyDeclaringClass(String name, LinkedList<T> properties) { Iterator<T> it = properties.iterator(); T property = it.next(); for (; it.hasNext(); ) { T next = it.next(); // Doesn't matter which one will be used, we want to merge the metadata next.updateBoth(property); // 1 we search the most specialized class containing this property // with highest priority if ((property.declaringClass.equals(next.declaringClass) && property.priority() < next.priority()) || property.declaringClass.isAssignableFrom(next.declaringClass)) { property = next; } else continue; } return property; }
@Override public Converter create(BeanProperty property, Genson genson) { if (!Temporal.class.isAssignableFrom(property.getRawClass())) return null; // only deal with java.time String format = null, lang = null; Format cfg1 = property.getAnnotation(Format.class); // support simter Format annotation if (null != cfg1) { format = cfg1.value(); lang = cfg1.lang(); } else { JsonDateFormat cfg2 = property.getAnnotation(JsonDateFormat.class); // support genson JsonDateFormat annotation if (null != cfg2) { format = cfg2.value(); lang = cfg2.lang(); } } return getConverter(property.getRawClass(), format, lang); }
@SuppressWarnings("unchecked") @Override public Converter<Object> create(BeanProperty property, Genson genson) { JsonConverter ann = property.getAnnotation(JsonConverter.class); if (ann != null) { Type converterExpandedType = expandType( Type converterPropertyType = typeOf(0, converterExpandedType); Class<?> propertyClass = property.getRawClass(); if (propertyClass.isPrimitive()) propertyClass = wrap(propertyClass); + " is not assignale from property " + property.getName() + " declared in " + property.getDeclaringClass());
@Override public Converter<Object> create(BeanProperty property, Genson genson) { XmlJavaTypeAdapter ann = property.getAnnotation(XmlJavaTypeAdapter.class); Converter<Object> converter = null; Type adaptedType = typeOf(0, adapterExpandedType); Type originalType = typeOf(1, adapterExpandedType); Type propertyType = property.getType(); XmlElement el = property.getAnnotation(XmlElement.class); Type xmlElementType = el != null && el.type() != XmlElement.DEFAULT.class ? el.type() : null; if (!match(adaptedType, xmlElementType, false)) throw new ClassCastException("The BoundType of XMLAdapter " + adapterClass + " is not assignable from property " + property.getName() + " declared in " + property.getDeclaringClass()); + " is not assignable from property " + property.getName() + " declared in " + property.getDeclaringClass());
@Override public Converter create(BeanProperty property, Genson genson) { if(hasRelevantAnnotation(property)) { Class<?> rawClass = property.getRawClass(); for (Map.Entry<Class<?>, ConverterGenerator> supportedType : converterGenerators.entrySet()) { Class<?> clazz = supportedType.getKey(); ConverterGenerator generator = supportedType.getValue(); if (clazz.isAssignableFrom(rawClass)) { DateTimeConverterOptions options = createOptions(property, clazz); return generator.createConverter(options); } } } return null; }
Converter<?> provide(BeanProperty property, Genson genson) { Type type = property.getType(); for (Iterator<? extends ContextualFactory<?>> it = contextualFactories.iterator(); it .hasNext(); ) { ContextualFactory<?> factory = it.next(); Converter<?> object = null; Type factoryType = lookupGenericType(ContextualFactory.class, factory.getClass()); factoryType = expandType(factoryType, factory.getClass()); Type factoryParameter = typeOf(0, factoryType); if (type instanceof Class<?> && ((Class<?>) type).isPrimitive()) type = wrap((Class<?>) type); if (match(type, factoryParameter, false) && (object = factory.create(property, genson)) != null) { return object; } } return null; } }
@Override public Converter create(BeanProperty property, Genson genson) { JsonDateFormat ann = property.getAnnotation(JsonDateFormat.class); if (ann != null) { if (MutableDateTime.class.isAssignableFrom(property.getRawClass())) { return makeMutableDateTimeConverter(ann.asTimeInMillis(), formatter(ann, dateTimeFormatter)); } else if (DateTime.class.isAssignableFrom(property.getRawClass())) { return makeDateTimeConverter(ann.asTimeInMillis(), formatter(ann, dateTimeFormatter)); } // local formats else if (LocalDate.class.isAssignableFrom(property.getRawClass())) { return makeLocalDateConverter(formatter(ann, localDateFormatter)); } else if (LocalDateTime.class.isAssignableFrom(property.getRawClass())) { return makeLocalDateTimeConverter(formatter(ann, localDateTimeFormatter)); } else if (LocalTime.class.isAssignableFrom(property.getRawClass())) { return makeLocalTimeConverter(formatter(ann, localTimeFormatter)); } } return null; }
@SuppressWarnings("unchecked") @Override public Converter<Object> create(BeanProperty property, Genson genson) { JsonConverter ann = property.getAnnotation(JsonConverter.class); if (ann != null) { Type converterExpandedType = expandType( Type converterPropertyType = typeOf(0, converterExpandedType); Class<?> propertyClass = property.getRawClass(); if (propertyClass.isPrimitive()) propertyClass = wrap(propertyClass); + " is not assignale from property " + property.getName() + " declared in " + property.getDeclaringClass());
@Override public Converter<Object> create(BeanProperty property, Genson genson) { XmlJavaTypeAdapter ann = property.getAnnotation(XmlJavaTypeAdapter.class); Converter<Object> converter = null; Type adaptedType = typeOf(0, adapterExpandedType); Type originalType = typeOf(1, adapterExpandedType); Type propertyType = property.getType(); XmlElement el = property.getAnnotation(XmlElement.class); Type xmlElementType = el != null && el.type() != XmlElement.DEFAULT.class ? el.type() : null; if (!match(adaptedType, xmlElementType, false)) throw new ClassCastException("The BoundType of XMLAdapter " + adapterClass + " is not assignable from property " + property.getName() + " declared in " + property.getDeclaringClass()); + " is not assignable from property " + property.getName() + " declared in " + property.getDeclaringClass());
Converter<?> provide(BeanProperty property, Genson genson) { Type type = property.getType(); for (Iterator<? extends ContextualFactory<?>> it = contextualFactories.iterator(); it .hasNext(); ) { ContextualFactory<?> factory = it.next(); Converter<?> object = null; Type factoryType = lookupGenericType(ContextualFactory.class, factory.getClass()); factoryType = expandType(factoryType, factory.getClass()); Type factoryParameter = typeOf(0, factoryType); if (type instanceof Class<?> && ((Class<?>) type).isPrimitive()) type = wrap((Class<?>) type); if (match(type, factoryParameter, false) && (object = factory.create(property, genson)) != null) { return object; } } return null; } }
@Override public Converter create(BeanProperty property, Genson genson) { JsonDateFormat ann = property.getAnnotation(JsonDateFormat.class); if (ann != null) { if (MutableDateTime.class.isAssignableFrom(property.getRawClass())) { return makeMutableDateTimeConverter(ann.asTimeInMillis(), formatter(ann, dateTimeFormatter)); } else if (DateTime.class.isAssignableFrom(property.getRawClass())) { return makeDateTimeConverter(ann.asTimeInMillis(), formatter(ann, dateTimeFormatter)); } // local formats else if (LocalDate.class.isAssignableFrom(property.getRawClass())) { return makeLocalDateConverter(formatter(ann, localDateFormatter)); } else if (LocalDateTime.class.isAssignableFrom(property.getRawClass())) { return makeLocalDateTimeConverter(formatter(ann, localDateTimeFormatter)); } else if (LocalTime.class.isAssignableFrom(property.getRawClass())) { return makeLocalTimeConverter(formatter(ann, localTimeFormatter)); } } return null; }
public String[] aliases() { JsonProperty ann = getAnnotation(JsonProperty.class); return ann != null ? ann.aliases() : new String[]{}; }
protected <T extends BeanProperty> T _mostSpecificPropertyDeclaringClass(String name, LinkedList<T> properties) { Iterator<T> it = properties.iterator(); T property = it.next(); for (; it.hasNext(); ) { T next = it.next(); // Doesn't matter which one will be used, we want to merge the metadata next.updateBoth(property); // 1 we search the most specialized class containing this property // with highest priority if ((property.declaringClass.equals(next.declaringClass) && property.priority() < next.priority()) || property.declaringClass.isAssignableFrom(next.declaringClass)) { property = next; } else continue; } return property; }
@Override public Converter create(BeanProperty property, Genson genson) { JsonDateFormat ann = property.getAnnotation(JsonDateFormat.class); if (ann != null) { Locale locale = ann.lang().isEmpty() ? Locale.getDefault() : new Locale( ann.lang()); DateFormat dateFormat = ann.value() != null && !ann.value().isEmpty() ? new SimpleDateFormat(ann.value(), locale) : SimpleDateFormat.getInstance(); if (Date.class.isAssignableFrom(property.getRawClass())) return new DateConverter(dateFormat, ann.asTimeInMillis()); if (Calendar.class.isAssignableFrom(property.getRawClass())) return new CalendarConverter( new DateConverter(dateFormat, ann.asTimeInMillis())); } return null; } }
public String[] aliases() { JsonProperty ann = getAnnotation(JsonProperty.class); return ann != null ? ann.aliases() : new String[]{}; }
@Override public Converter create(BeanProperty property, Genson genson) { JsonDateFormat ann = property.getAnnotation(JsonDateFormat.class); if (ann != null) { Locale locale = ann.lang().isEmpty() ? Locale.getDefault() : new Locale( ann.lang()); DateFormat dateFormat = ann.value() != null && !ann.value().isEmpty() ? new SimpleDateFormat(ann.value(), locale) : SimpleDateFormat.getInstance(); if (Date.class.isAssignableFrom(property.getRawClass())) return new DateConverter(dateFormat, ann.asTimeInMillis()); if (Calendar.class.isAssignableFrom(property.getRawClass())) return new CalendarConverter( new DateConverter(dateFormat, ann.asTimeInMillis())); } return null; } }