@Override public Object readFrom( Class<Object> clazz, Type type, Annotation[] antns, MediaType mt, MultivaluedMap<String, String> mm, InputStream in) throws IOException, WebApplicationException { BrwsrCtx def = BrwsrCtx.findDefault(HtmlJsonProvider.class); if (clazz.isArray()) { List<Object> res = new ArrayList<Object>(); final Class<?> cmp = clazz.getComponentType(); Models.parse(def, cmp, in, res); Object[] arr = (Object[]) Array.newInstance(cmp, res.size()); return res.toArray(arr); } if (clazz.isAssignableFrom(java.util.List.class) && type instanceof ParameterizedType && ((ParameterizedType) type).getActualTypeArguments().length == 1 && ((ParameterizedType) type).getActualTypeArguments()[0] instanceof Class) { List<Object> res = new ArrayList<Object>(); final Class<?> cmp = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0]; Models.parse(def, cmp, in, res); return res; } return Models.parse(def, clazz, in); }
@Override public boolean isWriteable(Class clazz, Type type, Annotation[] antns, MediaType mt) { if (!mt.isCompatible(MediaType.APPLICATION_JSON_TYPE)) { return false; } if (clazz.isArray()) { return Models.isModel(clazz.getComponentType()); } if (java.util.List.class.isAssignableFrom(clazz)) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; Type[] args = pt.getActualTypeArguments(); if (args.length == 1 && args[0] instanceof Class) { return Models.isModel((Class<?>) args[0]); } } } return Models.isModel(clazz); }