@Test public void shouldParseMultiplePreconditions() throws Exception { final String jsonHomeDocument = "{\n" + " \"resources\" : {" + "\"http: " \"href\" : \"http: " \"hints\" : {\n" + " \"precondition-req\" : [\"etag\", \"last-modified\"]\n" + " }\n" + " }}}"; final JsonHome jsonHome = new JacksonJsonHomeParser() .parse(new ByteArrayInputStream(jsonHomeDocument.getBytes())); assertEquals(jsonHome, jsonHome( directLink( create("http: create("http: hintsBuilder() .requiring(ETAG, LAST_MODIFIED) .build() ) )); }
@Override public JsonHome parse(final InputStream stream) { try { final JsonNode jsonNode = OBJECT_MAPPER.readTree(stream); if (jsonNode != null && jsonNode.has("resources")) { final JsonHomeBuilder builder = jsonHomeBuilder(); final JsonNode resourcesNode = jsonNode.get("resources"); final Iterator<String> fieldNames = resourcesNode.getFieldNames(); while (fieldNames.hasNext()) { final String fieldName = fieldNames.next(); final JsonNode resourceNode = resourcesNode.get(fieldName); builder.addResource(resourceLinkFrom(URI.create(fieldName), resourceNode)); } return builder.build(); } } catch (final JsonProcessingException e) { LOG.error("Unable to parse json-home document: {}", e.getMessage()); throw new IllegalArgumentException("Error parsing json-home document: " + e.getMessage(), e); } catch (final IOException e) { LOG.error("Unable to get json-home from stream: {}", e.getMessage()); throw new IllegalStateException("Unable to get json-home document from stream: " + e.getMessage(), e); } throw new IllegalArgumentException("Unable to parse json-home document: no resources defined."); }
JacksonJsonHomeParser implements JsonHomeParser { @Override public JsonHome parse(final InputStream stream) { try { final JsonNode jsonNode = OBJECT_MAPPER.readTree(stream); if (jsonNode != null && jsonNode.has("resources")) { final JsonHomeBuilder builder = jsonHomeBuilder(); final JsonNode resourcesNode = jsonNode.get("resources"); final Iterator<String> fieldNames = resourcesNode.getFieldNames(); while (fieldNames.hasNext()) { final String fieldName = fieldNames.next(); final JsonNode resourceNode = resourcesNode.get(fieldName); builder.addResource(resourceLinkFrom(URI.create(fieldName), resourceNode)); } return builder.build(); } } catch (final JsonProcessingException e) { LOG.error("Unable to parse json-home document: {}", e.getMessage()); throw new IllegalArgumentException("Error parsing json-home document: " + e.getMessage(), e); } catch (final IOException e) { LOG.error("Unable to get json-home from stream: {}", e.getMessage()); throw new IllegalStateException("Unable to get json-home document from stream: " + e.getMessage(), e); } throw new IllegalArgumentException("Unable to parse json-home document: no resources defined."); } }
JacksonJsonHomeParser implements JsonHomeParser { @Override public JsonHome parse(final InputStream stream) { try { final JsonNode jsonNode = OBJECT_MAPPER.readTree(stream); if (jsonNode != null && jsonNode.has("resources")) { final JsonHomeBuilder builder = jsonHomeBuilder(); final JsonNode resourcesNode = jsonNode.get("resources"); final Iterator<String> fieldNames = resourcesNode.getFieldNames(); while (fieldNames.hasNext()) { final String fieldName = fieldNames.next(); final JsonNode resourceNode = resourcesNode.get(fieldName); builder.addResource(resourceLinkFrom(URI.create(fieldName), resourceNode)); } return builder.build(); } } catch (final JsonProcessingException e) { LOG.error("Unable to parse json-home document: {}", e.getMessage()); throw new IllegalArgumentException("Error parsing json-home document: " + e.getMessage(), e); } catch (final IOException e) { LOG.error("Unable to get json-home from stream: {}", e.getMessage()); throw new IllegalStateException("Unable to get json-home document from stream: " + e.getMessage(), e); } throw new IllegalArgumentException("Unable to parse json-home document: no resources defined."); }  }
JacksonJsonHomeParser implements JsonHomeParser { @Override public JsonHome parse(final InputStream stream) { try { final JsonNode jsonNode = OBJECT_MAPPER.readTree(stream); if (jsonNode != null && jsonNode.has("resources")) { final JsonHomeBuilder builder = jsonHomeBuilder(); final JsonNode resourcesNode = jsonNode.get("resources"); final Iterator<String> fieldNames = resourcesNode.getFieldNames(); while (fieldNames.hasNext()) { final String fieldName = fieldNames.next(); final JsonNode resourceNode = resourcesNode.get(fieldName); builder.addResource(resourceLinkFrom(URI.create(fieldName), resourceNode)); } return builder.build(); } } catch (final JsonProcessingException e) { LOG.error("Unable to parse json-home document: {}", e.getMessage()); throw new IllegalArgumentException("Error parsing json-home document: " + e.getMessage(), e); } catch (final IOException e) { LOG.error("Unable to get json-home from stream: {}", e.getMessage()); throw new IllegalStateException("Unable to get json-home document from stream: " + e.getMessage(), e); } throw new IllegalArgumentException("Unable to parse json-home document: no resources defined."); }  @Override JsonHome parse(final InputStream stream); }
JacksonJsonHomeParser implements JsonHomeParser { @Override public JsonHome parse(final InputStream stream) { try { final JsonNode jsonNode = OBJECT_MAPPER.readTree(stream); if (jsonNode != null && jsonNode.has("resources")) { final JsonHomeBuilder builder = jsonHomeBuilder(); final JsonNode resourcesNode = jsonNode.get("resources"); final Iterator<String> fieldNames = resourcesNode.getFieldNames(); while (fieldNames.hasNext()) { final String fieldName = fieldNames.next(); final JsonNode resourceNode = resourcesNode.get(fieldName); builder.addResource(resourceLinkFrom(URI.create(fieldName), resourceNode)); } return builder.build(); } } catch (final JsonProcessingException e) { LOG.error("Unable to parse json-home document: {}", e.getMessage()); throw new IllegalArgumentException("Error parsing json-home document: " + e.getMessage(), e); } catch (final IOException e) { LOG.error("Unable to get json-home from stream: {}", e.getMessage()); throw new IllegalStateException("Unable to get json-home document from stream: " + e.getMessage(), e); } throw new IllegalArgumentException("Unable to parse json-home document: no resources defined."); }  @Override JsonHome parse(final InputStream stream); static final ObjectMapper OBJECT_MAPPER; }