Java Code Examples for com.alibaba.dubbo.common.utils.ReflectUtils#desc2class()

The following examples show how to use com.alibaba.dubbo.common.utils.ReflectUtils#desc2class() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JacksonObjectInput.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
    public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
//        Object value = readObject();
        //read data value
        String json = this.data.get(KEY_PREFIX + (++index));
        //read data type
        String dataType = this.data.get(KEY_PREFIX + index + "t");
        if (dataType != null) {
            Class clazz = ReflectUtils.desc2class(dataType);
            if (cls.isAssignableFrom(clazz)) {
                cls = clazz;
            } else {
                throw new IllegalArgumentException("Class \"" + clazz + "\" is not inherited from \"" + cls + "\"");
            }
        }
        logger.debug("index:{}, value:{}", index, json);
        return objectMapper.readValue(json, cls);
    }
 
Example 2
Source File: JacksonObjectInput.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
    public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
//        Object value = readObject();
        //read data value
        String json = this.data.get(KEY_PREFIX + (++index));
        //read data type
        String dataType = this.data.get(KEY_PREFIX + index + "t");
        if (dataType != null) {
            Class clazz = ReflectUtils.desc2class(dataType);
            if (cls.isAssignableFrom(clazz)) {
                cls = clazz;
            } else {
                throw new IllegalArgumentException("Class \"" + clazz + "\" is not inherited from \"" + cls + "\"");
            }
        }
        logger.debug("index:{}, value:{}", index, json);
        return objectMapper.readValue(json, cls);
    }
 
Example 3
Source File: JacksonObjectInput.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
    public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
//        Object value = readObject();
        //read data value
        String json = this.data.get(KEY_PREFIX + (++index));
        //read data type
        String dataType = this.data.get(KEY_PREFIX + index + "t");
        if (dataType != null) {
            Class clazz = ReflectUtils.desc2class(dataType);
            if (cls.isAssignableFrom(clazz)) {
                cls = clazz;
            } else {
                throw new IllegalArgumentException("Class \"" + clazz + "\" is not inherited from \"" + cls + "\"");
            }
        }
        logger.debug("index:{}, value:{}", index, json);
        return objectMapper.readValue(json, cls);
    }
 
Example 4
Source File: JacksonObjectInput.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
    public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
//        Object value = readObject();
        //read data value
        String json = this.data.get(KEY_PREFIX + (++index));
        //read data type
        String dataType = this.data.get(KEY_PREFIX + index + "t");
        if (dataType != null) {
            Class clazz = ReflectUtils.desc2class(dataType);
            if (cls.isAssignableFrom(clazz)) {
                cls = clazz;
            } else {
                throw new IllegalArgumentException("Class \"" + clazz + "\" is not inherited from \"" + cls + "\"");
            }
        }
        logger.debug("index:{}, value:{}", index, json);
        return objectMapper.readValue(json, cls);
    }
 
Example 5
Source File: GenericObjectInput.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Object readObject() throws IOException
{
	String desc;
	byte b = read0();

	switch( b )
	{
		case OBJECT_NULL:
			return null;
		case OBJECT_DUMMY:
			return new Object();
		case OBJECT_DESC:
		{
			desc = readUTF();
			break;
		}
		case OBJECT_DESC_ID:
		{
			int index = readUInt();
			desc = mMapper.getDescriptor(index);
			if( desc == null )
				throw new IOException("Can not find desc id: " + index );
			break;
		}
		default:
			throw new IOException("Flag error, expect OBJECT_NULL|OBJECT_DUMMY|OBJECT_DESC|OBJECT_DESC_ID, get " + b);
	}
	try
	{
		Class<?> c = ReflectUtils.desc2class(desc);
		return Builder.register(c).parseFrom(this);
	}
	catch(ClassNotFoundException e)
	{
		throw new IOException("Read object failed, class not found. " + StringUtils.toString(e));
	}
}
 
Example 6
Source File: GenericObjectInput.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Object readObject() throws IOException
{
	String desc;
	byte b = read0();

	switch( b )
	{
		case OBJECT_NULL:
			return null;
		case OBJECT_DUMMY:
			return new Object();
		case OBJECT_DESC:
		{
			desc = readUTF();
			break;
		}
		case OBJECT_DESC_ID:
		{
			int index = readUInt();
			desc = mMapper.getDescriptor(index);
			if( desc == null )
				throw new IOException("Can not find desc id: " + index );
			break;
		}
		default:
			throw new IOException("Flag error, expect OBJECT_NULL|OBJECT_DUMMY|OBJECT_DESC|OBJECT_DESC_ID, get " + b);
	}
	try
	{
		Class<?> c = ReflectUtils.desc2class(desc);
		return Builder.register(c).parseFrom(this);
	}
	catch(ClassNotFoundException e)
	{
		throw new IOException("Read object failed, class not found. " + StringUtils.toString(e));
	}
}
 
Example 7
Source File: GenericObjectInput.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Object readObject() throws IOException {
    String desc;
    byte b = read0();

    switch (b) {
        case OBJECT_NULL:
            return null;
        case OBJECT_DUMMY:
            return new Object();
        case OBJECT_DESC: {
            desc = readUTF();
            break;
        }
        case OBJECT_DESC_ID: {
            int index = readUInt();
            desc = mMapper.getDescriptor(index);
            if (desc == null)
                throw new IOException("Can not find desc id: " + index);
            break;
        }
        default:
            throw new IOException("Flag error, expect OBJECT_NULL|OBJECT_DUMMY|OBJECT_DESC|OBJECT_DESC_ID, get " + b);
    }
    try {
        Class<?> c = ReflectUtils.desc2class(desc);
        return Builder.register(c).parseFrom(this);
    } catch (ClassNotFoundException e) {
        throw new IOException("Read object failed, class not found. " + StringUtils.toString(e));
    }
}
 
Example 8
Source File: GenericObjectInput.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Object readObject() throws IOException
{
	String desc;
	byte b = read0();

	switch( b )
	{
		case OBJECT_NULL:
			return null;
		case OBJECT_DUMMY:
			return new Object();
		case OBJECT_DESC:
		{
			desc = readUTF();
			break;
		}
		case OBJECT_DESC_ID:
		{
			int index = readUInt();
			desc = mMapper.getDescriptor(index);
			if( desc == null )
				throw new IOException("Can not find desc id: " + index );
			break;
		}
		default:
			throw new IOException("Flag error, expect OBJECT_NULL|OBJECT_DUMMY|OBJECT_DESC|OBJECT_DESC_ID, get " + b);
	}
	try
	{
		Class<?> c = ReflectUtils.desc2class(desc);
		return Builder.register(c).parseFrom(this);
	}
	catch(ClassNotFoundException e)
	{
		throw new IOException("Read object failed, class not found. " + StringUtils.toString(e));
	}
}
 
Example 9
Source File: GenericObjectInput.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Object readObject() throws IOException
{
	String desc;
	byte b = read0();

	switch( b )
	{
		case OBJECT_NULL:
			return null;
		case OBJECT_DUMMY:
			return new Object();
		case OBJECT_DESC:
		{
			desc = readUTF();
			break;
		}
		case OBJECT_DESC_ID:
		{
			int index = readUInt();
			desc = mMapper.getDescriptor(index);
			if( desc == null )
				throw new IOException("Can not find desc id: " + index );
			break;
		}
		default:
			throw new IOException("Flag error, expect OBJECT_NULL|OBJECT_DUMMY|OBJECT_DESC|OBJECT_DESC_ID, get " + b);
	}
	try
	{
		Class<?> c = ReflectUtils.desc2class(desc);
		return Builder.register(c).parseFrom(this);
	}
	catch(ClassNotFoundException e)
	{
		throw new IOException("Read object failed, class not found. " + StringUtils.toString(e));
	}
}