List of usage examples for com.fasterxml.jackson.databind JavaType getRawClass
public final Class<?> getRawClass()
From source file:org.javafunk.funk.jackson.FunkSerializers.java
@Override public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) { checkNotNull(type);/*from ww w . jav a 2 s. c o m*/ Class<?> raw = type.getRawClass(); if (Option.class.isAssignableFrom(raw)) { return new OptionSerializer(type); } return super.findSerializer(config, type, beanDesc); }
From source file:javaslang.jackson.datatype.deserialize.SetDeserializer.java
@SuppressWarnings("unchecked") @Override/* ww w . j a v a 2s . c o m*/ Set<?> create(List<Object> result, DeserializationContext ctx) throws JsonMappingException { if (javaslang.collection.SortedSet.class.isAssignableFrom(javaType.getRawClass())) { if (javaType.containedTypeCount() == 0) { throw ctx.mappingException(javaType.getRawClass()); } JavaType generic = javaType.containedType(0); if (generic.getRawClass() == Object.class || !Comparable.class.isAssignableFrom(generic.getRawClass())) { throw ctx.mappingException(javaType.getRawClass()); } return javaslang.collection.TreeSet.ofAll((o1, o2) -> ((Comparable) o1).compareTo(o2), result); } if (javaslang.collection.LinkedHashSet.class.isAssignableFrom(javaType.getRawClass())) { return javaslang.collection.LinkedHashSet.ofAll(result); } // default deserialization [...] -> Set return HashSet.ofAll(result); }
From source file:javaslang.jackson.datatype.serialize.ValueSerializer.java
@Override public void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOException { Object obj = toJavaObj(value); if (obj == null) { provider.getDefaultNullValueSerializer().serialize(null, gen, provider); } else {/*from w w w .j a v a 2 s. co m*/ JsonSerializer<Object> ser; try { JavaType emulated = emulatedJavaType(type); if (emulated.getRawClass() != Object.class) { ser = provider.findTypedValueSerializer(emulated, true, null); } else { ser = provider.findTypedValueSerializer(obj.getClass(), true, null); } } catch (Exception ignore) { ser = provider.findTypedValueSerializer(obj.getClass(), true, null); } ser.serialize(obj, gen, provider); } }
From source file:javaslang.jackson.datatype.serialize.EitherSerializer.java
private void write(Object val, int containedTypeIndex, JsonGenerator gen, SerializerProvider provider) throws IOException { if (val != null) { if (type.containedTypeCount() > containedTypeIndex) { JsonSerializer<Object> ser; JavaType containedType = type.containedType(containedTypeIndex); if (containedType.getRawClass() != Object.class) { ser = provider.findTypedValueSerializer(type.containedType(containedTypeIndex), true, null); } else { ser = provider.findTypedValueSerializer(val.getClass(), true, null); }//from w w w . ja v a 2 s .c om ser.serialize(val, gen, provider); } else { gen.writeObject(val); } } else { gen.writeNull(); } }
From source file:net.nullschool.grains.jackson.datatype.GrainsAnnotationIntrospector.java
@Override public Class<?> findSerializationKeyType(Annotated annotated, JavaType keyType) { return keyType != null ? publicInterfaceOf(keyType.getRawClass()) : null; }
From source file:com.wealdtech.jackson.modules.TriValDeserializers.java
@Override public JsonDeserializer<?> findBeanDeserializer(final JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { Class<?> raw = type.getRawClass(); if (TriVal.class.isAssignableFrom(raw)) { return new TriValDeserializer(type); }//from w w w . j a va 2 s. co m return super.findBeanDeserializer(type, config, beanDesc); }
From source file:org.brutusin.json.impl.JacksonFactoryWrapper.java
@Override public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType) { String format = getFormat(convertedType.getRawClass()); if (format != null) { StringSchema s = (StringSchema) schemaProvider.stringSchema(); s.setStringFormat(format);// w w w . ja v a 2s. c o m schema = s; return null; } return super.expectAnyFormat(convertedType); }
From source file:org.javafunk.funk.jackson.FunkDeserializers.java
@Override public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { Class<?> raw = type.getRawClass(); if (Option.class.isAssignableFrom(raw)) { TypeDeserializer typeHandler = type.getTypeHandler(); JsonDeserializer<?> valueHandler = type.getValueHandler(); return new OptionDeserializer(type, option(typeHandler), Option.<JsonDeserializer<?>>option(valueHandler)); }//from ww w . jav a 2s .c o m return super.findBeanDeserializer(type, config, beanDesc); }
From source file:org.mongojack.internal.MongoAnnotationIntrospector.java
public JsonDeserializer findObjectIdDeserializer(JavaType type) { if (type.getRawClass() == String.class) { return new ObjectIdDeserializers.ToStringDeserializer(); } else if (type.getRawClass() == byte[].class) { return new ObjectIdDeserializers.ToByteArrayDeserializer(); } else if (type.getRawClass() == DBRef.class) { JavaType dbRefType;/*w w w . j a v a2 s. co m*/ if (type.isContainerType()) { if (type.isCollectionLikeType()) { dbRefType = type.containedType(0); } else if (type.isMapLikeType()) { dbRefType = type.containedType(1); } else { return null; } } else { dbRefType = type; } JsonDeserializer keyDeserializer = findObjectIdDeserializer(dbRefType.containedType(1)); return new DBRefDeserializer(dbRefType.containedType(0), dbRefType.containedType(1), keyDeserializer); } else if (type.getRawClass() == org.bson.types.ObjectId.class) { // Don't know why someone would annotated an ObjectId with // @ObjectId, but handle it return new ObjectIdDeserializers.ToObjectIdDeserializer(); } return null; }
From source file:net.nullschool.grains.jackson.datatype.GrainsAnnotationIntrospector.java
@Override public Class<?> findSerializationContentType(Annotated annotated, JavaType contentType) { return contentType != null ? publicInterfaceOf(contentType.getRawClass()) : null; }