Created
January 15, 2014 20:20
-
-
Save hamnis/8443786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkTypeExt extends Extension<Optional<String>>{ | |
@Override | |
public Optional<String> extract(ObjectNode node) { | |
return node.has("type") ? Optional.some(node.get("type").asText()) : Optional.<String>none(); | |
} | |
@Override | |
public Map<String, JsonNode> apply(Optional<String> value) { | |
if (value.isSome()) { | |
return Collections.singletonMap("type", ValueFactory.createValue(value.get()).asJson()); | |
} | |
return Collections.emptyMap(); | |
} | |
public static void main(String[] args) { | |
Collection c = ...; | |
Optional<Link> alternate = c.linkByRel("alternate"); | |
for (Link link : alternate) { | |
Optional<String> typeOpt = link.getExtension(new LinkTypeExt()); | |
for (String type : typeOpt) { | |
System.out.println("type = " + type); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment