protected void _reportIncompatibleRootType(Object value, JavaType rootType) throws IOException { // One special case: allow primitive/wrapper type coercion if (rootType.isPrimitive()) { Class<?> wrapperType = ClassUtil.wrapperType(rootType.getRawClass()); // If it's just difference between wrapper, primitive, let it slide if (wrapperType.isAssignableFrom(value.getClass())) { return; } } reportBadDefinition(rootType, String.format( "Incompatible types: declared root type (%s) vs %s", rootType, ClassUtil.classNameOf(value))); }
private boolean _primitiveAndWrapper(JavaType baseType, Class<?> refinement) { if (baseType.isPrimitive()) { return baseType.hasRawClass(ClassUtil.primitiveType(refinement)); } if (refinement.isPrimitive()) { return refinement == ClassUtil.primitiveType(baseType.getRawClass()); } return false; } }
/** * Helper method called to get a description of type into which a scalar value coercion * is (most likely) being applied, to be used for constructing exception messages * on coerce failure. * * @return Message with backtick-enclosed name of type this deserializer supports * * @since 2.9 */ protected String _coercedTypeDesc() { boolean structured; String typeDesc; JavaType t = getValueType(); if ((t != null) && !t.isPrimitive()) { structured = (t.isContainerType() || t.isReferenceType()); // 21-Jul-2017, tatu: Probably want to change this (JavaType.toString() not very good) but... typeDesc = "'"+t.toString()+"'"; } else { Class<?> cls = handledType(); structured = cls.isArray() || Collection.class.isAssignableFrom(cls) || Map.class.isAssignableFrom(cls); typeDesc = ClassUtil.nameOf(cls); } if (structured) { return "as content of type "+typeDesc; } return "for type "+typeDesc; }
@Override public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes) { if (_idType == JsonTypeInfo.Id.NONE) { return null; } // 03-Oct-2016, tatu: As per [databind#1395] better prevent use for primitives, // regardless of setting if (baseType.isPrimitive()) { return null; } TypeIdResolver idRes = idResolver(config, baseType, subtypes, true, false); switch (_includeAs) { case WRAPPER_ARRAY: return new AsArrayTypeSerializer(idRes, null); case PROPERTY: return new AsPropertyTypeSerializer(idRes, null, _typeProperty); case WRAPPER_OBJECT: return new AsWrapperTypeSerializer(idRes, null); case EXTERNAL_PROPERTY: return new AsExternalTypeSerializer(idRes, null, _typeProperty); case EXISTING_PROPERTY: // as per [#528] return new AsExistingPropertyTypeSerializer(idRes, null, _typeProperty); } throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: "+_includeAs); }
@Override public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes) { if (_idType == JsonTypeInfo.Id.NONE) { return null; } // 03-Oct-2016, tatu: As per [databind#1395] better prevent use for primitives, // regardless of setting if (baseType.isPrimitive()) { return null; } TypeIdResolver idRes = idResolver(config, baseType, subtypes, false, true); JavaType defaultImpl = defineDefaultImpl(config, baseType); // First, method for converting type info to type id: switch (_includeAs) { case WRAPPER_ARRAY: return new AsArrayTypeDeserializer(baseType, idRes, _typeProperty, _typeIdVisible, defaultImpl); case PROPERTY: case EXISTING_PROPERTY: // as per [#528] same class as PROPERTY return new AsPropertyTypeDeserializer(baseType, idRes, _typeProperty, _typeIdVisible, defaultImpl, _includeAs); case WRAPPER_OBJECT: return new AsWrapperTypeDeserializer(baseType, idRes, _typeProperty, _typeIdVisible, defaultImpl); case EXTERNAL_PROPERTY: return new AsExternalTypeDeserializer(baseType, idRes, _typeProperty, _typeIdVisible, defaultImpl); } throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: "+_includeAs); }
if (t.isPrimitive()) { return false;
if (contentDeser == null) { Class<?> raw = elemType.getRawClass(); if (elemType.isPrimitive()) { return PrimitiveArrayDeserializers.forType(raw);
if (type.isAbstract() && !type.isPrimitive() && !type.isEnumType()) {
public BooleanSchema(Field protoField, PropertyDescriptor propertyDescriptor) { super(protoField, propertyDescriptor); this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter(); }
public StringSchema(Field protoField, PropertyDescriptor propertyDescriptor) { super(protoField, propertyDescriptor); this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter(); }
public DoubleSchema(Field protoField, PropertyDescriptor propertyDescriptor) { super(protoField, propertyDescriptor); this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter(); }
public EnumSchema(Field protoField, PropertyDescriptor propertyDescriptor) { super(protoField, propertyDescriptor); this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter(); }
public FloatSchema(Field protoField, PropertyDescriptor propertyDescriptor) { super(protoField, propertyDescriptor); this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter(); }
public FieldSchema(Field protoField, JavaType javaType) { this.protoField = protoField; this.name = protoField.getName(); this.fieldNumber = protoField.getTag(); this.packed = ProtoUtils.isPacked(protoField); int wireType = packed && protoField.isRepeated() ? WireFormat.WIRETYPE_LENGTH_DELIMITED : FieldTypeUtils.convert(protoField.getType()).wireType; this.tag = WireFormat.makeTag(fieldNumber, wireType); this.tagSize = ProtobufOutputEx.computeRawVarint32Size(tag); this.javaType = javaType; this.primitive = javaType.isPrimitive(); }
public String addSeenSchemaUri(JavaType aSeenSchema) { if (aSeenSchema != null && !aSeenSchema.isPrimitive()) { seenSchemas.add(aSeenSchema); return javaTypeToUrn(aSeenSchema); } return null; }
public String addSeenSchemaUri(JavaType aSeenSchema) { if (aSeenSchema != null && !aSeenSchema.isPrimitive()) { seenSchemas.add(aSeenSchema); return javaTypeToUrn(aSeenSchema); } return null; }
public NullProvider(JavaType type, Object nullValue) { _nullValue = nullValue; // [JACKSON-420] _isPrimitive = type.isPrimitive(); _rawType = type.getRawClass(); }
@Override public boolean useForType(JavaType t) { return !t.isPrimitive() && t.getRawClass() != ZonedDateTime.class; } }
/** * Returns true if no type info should be written for this base type. * * @param baseType Base type. * @return True to suppress writing of type information. */ private boolean noTypeInfo(JavaType baseType) { return baseType.isPrimitive() || baseType.isArrayType() || baseType.isCollectionLikeType() || Date.class.isAssignableFrom(baseType.getRawClass()); } }
private boolean _primitiveAndWrapper(JavaType baseType, Class<?> refinement) { if (baseType.isPrimitive()) { return baseType.hasRawClass(ClassUtil.primitiveType(refinement)); } if (refinement.isPrimitive()) { return refinement == ClassUtil.primitiveType(baseType.getRawClass()); } return false; } }