use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project incubator-servicecomb-java-chassis by apache.
the class ProtobufSchemaUtils method getOrCreateSchema.
// 适用于将单个类型包装的场景
// 比如return
public static WrapSchema getOrCreateSchema(Type type) {
JavaType javaType = TypeFactory.defaultInstance().constructType(type);
// List<String> -> java.util.List<java.lang.String>
// List<List<String>> -> java.util.List<java.util.List<java.lang.String>>
String key = javaType.toCanonical();
return getOrCreateSchema(key, () -> {
if (!isNeedWrap(javaType.getRawClass())) {
// 可以直接使用
Schema<?> schema = RuntimeSchema.createFrom(javaType.getRawClass());
return WrapSchemaFactory.createSchema(schema, WrapType.NOT_WRAP);
}
// 需要包装
WrapClassConfig config = new WrapClassConfig();
config.setType(WrapType.NORMAL_WRAP);
config.setClassName("gen.wrap.protobuf." + org.apache.servicecomb.swagger.generator.core.utils.ClassUtils.correctClassName(key));
if (!Void.TYPE.isAssignableFrom(javaType.getRawClass())) {
config.addField("field0", javaType);
}
JavassistUtils.genSingleWrapperInterface(config);
return createWrapSchema(config);
});
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project pmph by BCSquad.
the class JsonUtil method main.
@SuppressWarnings({ "deprecation", "unchecked" })
public static void main(String[] args) throws Exception {
// String jsonDecPosition =
// "[{'id':4,'chosenPosition':1,'rank':1,'isDigitalEditor':true},{'id':3,'chosenPosition':2,'rank':3,'isDigitalEditor':true},{'id':1,'chosenPosition':3,'rank':'','isDigitalEditor':false}]";
String jsonString = "[{'title':'你会网上冲浪吗?','type':1,'direction':null,'sort':1,'surveyQuestionOptionList':[{'optionContent':'不会'},{'optionContent':'会'}]},{'title':'你最喜欢的运动是什么','type':2,'direction':'','sort':'2','surveyQuestionOptionList':[{'optionContent':'篮球'},{'optionContent':'足球'},{'optionContent':'乒乓球'},{'optionContent':'羽毛球'},{'optionContent':'棒球'},{'optionContent':'网球'}]}]";
// JavaType javaType = getCollectionType(ArrayList.class, SurveyQuestionListVO.class);
// List<SurveyQuestionListVO> lst =
// (List<SurveyQuestionListVO>) objectMapper.readValue(jsonString, javaType);
// System.out.println(lst.toString());
// System.out.println(decode(jsonString, new TypeReference<SurveyQuestionListVO>() {
// }).toString());
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, SurveyQuestionListVO.class);
List<SurveyQuestionListVO> lst = (List<SurveyQuestionListVO>) objectMapper.readValue(jsonString, javaType);
// List<SurveyQuestionListVO> beanList =
// objectMapper.readValue(jsonString, new TypeReference<List<SurveyQuestionListVO>>() {
// });
System.out.println(lst.toString());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project keycloak by keycloak.
the class ObjectMapperResolver method createStreamSerializer.
public static ObjectMapper createStreamSerializer() {
ObjectMapper mapper = new ObjectMapper();
JavaType type = TypeFactory.unknownType();
JavaType streamType = mapper.getTypeFactory().constructParametricType(Stream.class, type);
SimpleModule module = new SimpleModule();
module.addSerializer(new StreamSerializer(streamType, type));
mapper.registerModule(module);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
if (Boolean.parseBoolean(System.getProperty("keycloak.jsonPrettyPrint", "false"))) {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
return mapper;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project cytoscape-impl by cytoscape.
the class PropertiesJsonDeserializer method readValue.
public static Object readValue(final String key, final String input, final ObjectMapper mapper, final AbstractCustomGraphics2<?> cg2) {
Object value = null;
final Class<?> type = cg2.getSettingType(key);
if (type != null) {
final TypeFactory typeFactory = mapper.getTypeFactory();
try {
if (type == Array.class) {
final Class<?> elementType = cg2.getSettingElementType(key);
if (elementType != null) {
final ArrayType arrType = typeFactory.constructArrayType(elementType);
if (mapper.canDeserialize(arrType))
value = mapper.readValue(input, arrType);
}
} else if (List.class.isAssignableFrom(type)) {
final Class<?> elementType = cg2.getSettingElementType(key);
if (elementType != null) {
final CollectionType collType = typeFactory.constructCollectionType(List.class, elementType);
if (mapper.canDeserialize(collType))
value = mapper.readValue(input, collType);
}
} else {
final JavaType simpleType = typeFactory.constructSimpleType(type, new JavaType[] {});
if (mapper.canDeserialize(simpleType))
value = mapper.readValue(input, simpleType);
}
} catch (Exception e) {
logger.error("Cannot parse JSON field " + key, e);
}
}
return value;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project spring-integration by spring-projects.
the class Jackson2JsonObjectMapper method extractJavaType.
@Override
@SuppressWarnings({ "unchecked" })
protected JavaType extractJavaType(Map<String, Object> javaTypes) throws Exception {
JavaType classType = this.createJavaType(javaTypes, JsonHeaders.TYPE_ID);
if (!classType.isContainerType() || classType.isArrayType()) {
return classType;
}
JavaType contentClassType = this.createJavaType(javaTypes, JsonHeaders.CONTENT_TYPE_ID);
if (classType.getKeyType() == null) {
return this.objectMapper.getTypeFactory().constructCollectionType((Class<? extends Collection<?>>) classType.getRawClass(), contentClassType);
}
JavaType keyClassType = this.createJavaType(javaTypes, JsonHeaders.KEY_TYPE_ID);
return this.objectMapper.getTypeFactory().constructMapType((Class<? extends Map<?, ?>>) classType.getRawClass(), keyClassType, contentClassType);
}
Aggregations