/** * Converts a Representation into a regular Java object. * * @param source * The source representation to convert. * @return The converted Java object. * @throws IOException */ public Object toObject(Representation source) throws IOException { return toObject(source, null, null); }
/** * Returns the entity as a higher-level object. This object is created by * the Application's converter service. In order to use this method to * facilitate the parsing of entities, you need to set an instance of a * subclass of ConverterService onto your Restlet Application, overriding * the toObject(Representation) method. <br> * Note that this triggers the parsing of the entity. * * @return The entity as a higher-level object. * @see org.restlet.service.ConverterService * @deprecated Since 1.1, the ConverterService is deprecated, with no * replacement as it doesn't fit well with content negotiation. * Most users prefer to handle those conversion in Resource * subclasses. */ @Deprecated public Object getEntityAsObject() { return getConverterService().toObject(getEntity()); }
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Representation sourceRepresentation = new InputRepresentation(entityStream, toRestletMediaType(mediaType)); return getConverterService().toObject(sourceRepresentation, type, null); }
/** * Converts a representation into a Java object. Leverages the * {@link org.restlet.service.ConverterService}. * * @param <T> * The expected class of the Java object. * @param source * The source representation to convert. * @param target * The target class of the Java object. * @return The converted Java object. * @throws ResourceException */ public <T> T toObject(Representation source, Class<T> target) throws ResourceException { T result = null; if (source != null) { try { org.restlet.service.ConverterService cs = getConverterService(); result = cs.toObject(source, target, this); } catch (ResourceException e) { throw e; } catch (Exception e) { throw new ResourceException( Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, e); } } return result; }