Code example for TypeDescriptor

Methods: getObjectType

0
     * @param sourceType 
     * @param targetType 
     * @return 
     */ 
    public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
        Class clazz = targetType.getObjectType();
        return clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class);
    } 
 
    public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(String.class, Object.class));
    } 
 
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
        try { 
            if (SimpleRopRequestContext.messageFormat.get() == MessageFormat.json) {//输入格式为JSON
                JsonParser jsonParser = objectMapper.getJsonFactory().createJsonParser((String) source);
                return jsonParser.readValueAs(targetType.getObjectType());
            } else { 
                Unmarshaller unmarshaller = createUnmarshaller(targetType.getObjectType());
Experience pair programming with AI  Get Codota for Java