use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.
the class SchemaManager method createMapFieldSchema.
protected <T> FieldSchema<T> createMapFieldSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
JavaType javaType = propertyDescriptor.getJavaType();
if (javaType.isJavaLangObject()) {
javaType = ProtoConst.MAP_TYPE;
}
JavaType entryType = TypeFactory.defaultInstance().constructParametricType(MapEntry.class, javaType.getKeyType(), javaType.getContentType());
SchemaEx<Entry<Object, Object>> entrySchema = getOrCreateMessageSchema((Message) protoField.getType(), entryType);
return new MapSchema<>(protoField, propertyDescriptor, entrySchema);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.
the class DeserializerSchemaManager method createRootDeserializer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> RootDeserializer<T> createRootDeserializer(Message message, Type type) {
if (ProtoUtils.isAnyMessage(message)) {
SchemaEx<Object> messageSchema = new AnyEntrySchema(protoMapper, type);
return new RootDeserializer(messageSchema);
}
JavaType javaType = TypeFactory.defaultInstance().constructType(type);
SchemaEx<T> messageSchema = getOrCreateMessageSchema(message, javaType);
return new RootDeserializer<>(messageSchema);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.
the class DeserializerSchemaManager method createRepeatedSchema.
@Override
protected <T> FieldSchema<T> createRepeatedSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
boolean packed = ProtoUtils.isPacked(protoField);
if (protoField.getType().isEnum()) {
return packed ? EnumPackedReadSchemas.create(protoField, propertyDescriptor) : EnumNotPackedReadSchemas.create(protoField, propertyDescriptor);
}
if (protoField.getType().isScalar()) {
switch((ScalarFieldType) protoField.getType()) {
case INT32:
return packed ? Int32PackedReadSchemas.create(protoField, propertyDescriptor) : Int32NotPackedReadSchemas.create(protoField, propertyDescriptor);
case UINT32:
return packed ? UInt32PackedReadSchemas.create(protoField, propertyDescriptor) : UInt32NotPackedReadSchemas.create(protoField, propertyDescriptor);
case SINT32:
return packed ? SInt32PackedReadSchemas.create(protoField, propertyDescriptor) : SInt32NotPackedReadSchemas.create(protoField, propertyDescriptor);
case FIXED32:
return packed ? Fixed32PackedReadSchemas.create(protoField, propertyDescriptor) : Fixed32NotPackedReadSchemas.create(protoField, propertyDescriptor);
case SFIXED32:
return packed ? SFixed32PackedReadSchemas.create(protoField, propertyDescriptor) : SFixed32NotPackedReadSchemas.create(protoField, propertyDescriptor);
case INT64:
return packed ? Int64PackedReadSchemas.create(protoField, propertyDescriptor) : Int64NotPackedReadSchemas.create(protoField, propertyDescriptor);
case UINT64:
return packed ? UInt64PackedReadSchemas.create(protoField, propertyDescriptor) : UInt64NotPackedReadSchemas.create(protoField, propertyDescriptor);
case SINT64:
return packed ? SInt64PackedReadSchemas.create(protoField, propertyDescriptor) : SInt64NotPackedReadSchemas.create(protoField, propertyDescriptor);
case FIXED64:
return packed ? Fixed64PackedReadSchemas.create(protoField, propertyDescriptor) : Fixed64NotPackedReadSchemas.create(protoField, propertyDescriptor);
case SFIXED64:
return packed ? SFixed64PackedReadSchemas.create(protoField, propertyDescriptor) : SFixed64NotPackedReadSchemas.create(protoField, propertyDescriptor);
case FLOAT:
return packed ? FloatPackedReadSchemas.create(protoField, propertyDescriptor) : FloatNotPackedReadSchemas.create(protoField, propertyDescriptor);
case DOUBLE:
return packed ? DoublePackedReadSchemas.create(protoField, propertyDescriptor) : DoubleNotPackedReadSchemas.create(protoField, propertyDescriptor);
case BOOL:
return packed ? BoolPackedReadSchemas.create(protoField, propertyDescriptor) : BoolNotPackedReadSchemas.create(protoField, propertyDescriptor);
case STRING:
return StringRepeatedReadSchemas.create(protoField, propertyDescriptor);
case BYTES:
return BytesRepeatedReadSchemas.create(protoField, propertyDescriptor);
}
}
if (ProtoUtils.isAnyField(protoField)) {
AnyEntrySchema anyEntrySchema = new AnyEntrySchema(protoMapper, null);
return AnyRepeatedReadSchemas.create(protoField, propertyDescriptor, anyEntrySchema);
}
if (protoField.getType().isMessage()) {
JavaType contentType = propertyDescriptor.getJavaType().getContentType();
if (contentType == null) {
contentType = ProtoConst.OBJECT_TYPE;
}
SchemaEx<Object> contentSchema = getOrCreateMessageSchema((Message) protoField.getType(), contentType);
if (isWrapProperty((Message) protoField.getType())) {
return PropertyWrapperRepeatedReadSchemas.create(protoField, propertyDescriptor, contentSchema);
}
return MessageRepeatedReadSchemas.create(protoField, propertyDescriptor, contentSchema);
}
ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
return null;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.
the class TestMessageSchema method generic.
@Test
public void generic() throws Throwable {
JavaType javaType = TypeFactory.defaultInstance().constructParametricType(CustomGeneric.class, User.class);
RootDeserializer<CustomGeneric<User>> genericDeserializer = protoMapper.createRootDeserializer("Root", javaType);
builder.setUser(ProtobufRoot.User.newBuilder().setName("name1").build());
check(genericDeserializer, mapRootDeserializer, rootSerializer, false);
@SuppressWarnings("unchecked") CustomGeneric<User> generic = (CustomGeneric<User>) scbRoot;
Assert.assertThat(generic.user, Matchers.instanceOf(User.class));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.
the class UInt64ReadSchemas method create.
public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
JavaType javaType = propertyDescriptor.getJavaType();
if (long.class.equals(javaType.getRawClass())) {
return new UInt64PrimitiveSchema<>(protoField, propertyDescriptor);
}
if (Long.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
return new UInt64Schema<>(protoField, propertyDescriptor);
}
ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
return null;
}
Aggregations