@Override public ServiceInstance<T> readFrom(Class<ServiceInstance<T>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { try { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.reader().readTree(entityStream); return readInstance(node, context); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); throw new WebApplicationException(e); } }
public Object readFrom(Resource resource, ClassLoader classLoader) throws Exception { InputStream stream = resource.getInputStream(); JsonNode node = mapper.reader(JsonNode.class).readTree(stream); if (node.isArray()) { Iterator<JsonNode> elements = node.getElements(); List<Object> result = new ArrayList<Object>(); while (elements.hasNext()) { JsonNode element = elements.next(); result.add(readSingle(element, classLoader)); } return result; } return readSingle(node, classLoader); }
@Override public ServiceNames readFrom(Class<ServiceNames> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { List<String> names = Lists.newArrayList(); ObjectMapper mapper = new ObjectMapper(); JsonNode tree = mapper.reader().readTree(entityStream); for ( int i = 0; i < tree.size(); ++i ) { JsonNode node = tree.get(i); names.add(node.get("name").asText()); } return new ServiceNames(names); }
@Override public ServiceInstances<T> readFrom(Class<ServiceInstances<T>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { try { List<ServiceInstance<T>> instances = Lists.newArrayList(); ObjectMapper mapper = new ObjectMapper(); JsonNode tree = mapper.reader().readTree(entityStream); for ( int i = 0; i < tree.size(); ++i ) { JsonNode node = tree.get(i); ServiceInstance<T> instance = JsonServiceInstanceMarshaller.readInstance(node, context); instances.add(instance); } return new ServiceInstances<T>(instances); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); throw new WebApplicationException(e); } }